things without the fear of destroying working stuff collaboration (avoid sending email attachments back and forth) merge work with others review before deploy work on multiple fronts at the same time go back in time; reproducible results
time Experiment new features without bothering others Commit changes often locally Local operations = fast Naturally have remote copies with full history (as backups)
make prefix=/path/to/git all $ make prefix=/path/to/git install Linux/GNU distros $ apt-get install git # debian/ubuntu $ yum install git # fedora/centos GUI installers available for Mac and Windows
Gibbons <peter@initech> Date: Wed Dec 18 11:32:04 2013 -0800 my first commit 40-character SHA-1 for every commit using content and parent commit File integrity guaranteed
directory you edit files here 2. Staging area a file is staged after running “git add” stage the file state at the time of “git add” changes after “git add” is not staged 3. git directory (repository, or the “database”) after running “git commit”
[email protected]:user/repo 2. Work locally (your laptop) $ emacs $ git commit 3. Fetch and merge newer commits since last pull/clone $ git pull origin 4. Push back to remote $ git push origin # if you have write access
(no merge) $ git fetch origin Manually merge when you want to (into your branch): $ git checkout your_branch $ git merge Push merged result to remote $ git push origin # if you have write access
want to disturb current working version $ git branch mytest # create a new branch $ git checkout mytest # branch’s working directory or just $ git checkout -b mytest A powerful feature of git
a set of snapshots of a mini filesystem adding a pointer vs. copying data Other version control systems (CVS, Subversion, bazaar, etc) view the data as a set of files and ∆’s
enter the new branch $ git checkout -b mytest 2. Work in the new branch: test, commit all changes, etc. 3. (after review) merge “mytest” into “master” branch $ git checkout master # enter master branch $ git merge mytest # merge mytest into master 4. Delete the branch mytest (or not) $ git branch -d mytest
the same place in a file. This is not git-particular. This happens even if we do everything manually without git, e.g. Peter Gibbons and Bill Lumbergh have different says on the same line of code.
and <<<< stuff 2. Edit the file to the desired content $ emacs hello.c # edit to resolve conflicts $ cat hello.c int main() { return -1; } Once could also set up to use merge tools, e.g. $ git config --global merge.tool vimdiff
may use this approach to: collapse “noisy” commits into one to “hide” your trials and errors and make your commits look like they are in the right direction in every step you took :) rewrite commit message split commits . . . But do this with care. . .
bit pick 310154e updated README formatting and added blame pick a5f4a0d added cat-file # Rebase 710f0f8..a5f4a0d onto 710f0f8 # # Commands: # p, pick = use commit # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commi # # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be #
every commit, e.g. $ git filter-branch --tree-filter \ ’rm -f passwords.txt’ HEAD change email address globally . . . Note: git’s SHA is based on content, so this will change SHA of many commits, not just the ones you modify.
easy-to-use web interface, asethetically good looking access control made easy code/content review, commenting on particular lines get issue tracking, wiki “for free” pull request (PR) enabling collaboration You will want to do this anyway after your git server went down a few times :-)
convenient for small team could be “dangerous” if some contributors do not follow rules strictly (e.g. destablize code base) 2. Not everyone has write permission Team members fork from master, then send “pull request” Only maintainers can merge PR into master A natural “code review” process; very scalable still a good practice even if all contributors have write permission Pull request (aka “PR”) is a common practice.
1. (Mary) fork it into bitbucket.org/mary/cfd 2. (Mary) clone to her computer, work on it, then push changes back to bitbucket.org/mary/cfd. 3. (Mary) sends a pull request (in bitbucket) to Joe 4. (Joe) gets email notification; PR shows up in Joe’s account 5. (Joe) reviews changes, add comments. Mary revise changes, push new changes. Iterate until all are satisfied. 6. (Joe) merge Mary’s branch to his master branch in, delete Mary’s branch in bitbucket.org/joe/cfd 7. (Mary) may or may not delete her branch (in bitbucket.org/mary/cfd)
both personal projects and large projects with many branches Use git “branch” feature in your daily workflow git’s “killer feature” especially helpful when collaborating Take advantages of free hosting services to save your time github.com – free for public repos bitbucket.org – free for both public and private repos
is thinking git is a complete revision control system; it is not. Git, plus an organized mailing list that people actually respond to action items on, plus a rigid set of stylized bookkeeping done by each developer, plus a tyranical manager of the entire software development process is a complete revision control system.” – PETSc team