Why Git? • Distributed, not Centralized • Revolutionizes how you use branching • Extremely stupidly ridiculously fast, even with large projects • Community
Distributed VCS • Every Git working directory is a full-fledged repository with full revision tracking capabilities, not dependent on network access or a central server. • Commits happen offline. • Commits can then be pushed and pulled between repositories with shared history.
Why branching with Git is awesome • Instant $ time git checkout -b newbranch Switched to a new branch "newbranch" real
0m0.227s • Private • Merging doesn’t suck
Offline Operations • Performing a diff • Viewing file history • Committing changes • Merging branches • Obtaining any other revision of a file • Switching branches
One major difference • After making any changes to the working directory, and before running the commit command, you must use the add command to add any new or modified files to the index.
Example # create bar and to the index echo “foo” > bar git add bar # change bar, and thus remove from the index echo “ “ >> bar # add bar to the index again git add bar
Committing • git commit • commit what’s in the index • git commit -a • adds changed but not untracked files to the index, then commits • exactly like SVN
Diffs # diff between working tree and the index $ git diff # diff between the index and last commit $ git diff --cached # diff between working tree and last commit $ git diff HEAD
Logs # just like svn $ git log # find a commit changed a specific string $ git log -S"def stupid_method" # log with patches for each commit $ git log -p
Branching # create a new branch $ git branch NEW_BRANCH # switch to this branch $ git checkout NEW_BRANCH # create a new branch and check it out in one step $ git checkout -b NEW_BRANCH
Diffing and Logging with Branches # log of changes to other_branch not in master $ git log NEW_BRANCH..master # diff of those changes $ git diff NEW_BRANCH..master
Merging # get back to the master $ git checkout master # merge in changes from your other branch $ git merge NEW_BRANCH # optionally, delete the branch $ git branch -d NEW_BRANCH
Rebasing # store local changes not in BRANCH_NAME as patches, updates the local branch to BRANCH_NAME, then applies the patches $ git rebase BRANCH_NAME
Fork, then clone • Fork repo at github http://github.com/jnewland/atlrug-demo/tree/master • Clone your copy of my repo $ git clone [email protected]/USERNAME/atlrug-demo.git
Merge it all together # switch back to the master $ git checkout master # update master with your changes $ git merge my_branch # update master with upstream changes $ git merge jnewland/master