Intro to Git

Obligitory XKCD

It's really pretty simple...

Git is a tool for snapshotting with some really powerful tools for navigating and combining those snapshots

Installation

Follow Instructions

Initial configuration

Some common configuration options here. At a bare minimum, make sure you set your name and email

$ git config --global user.name "John Iacona"
$ git config --global user.email j.iacona@kew.org
          

Github

Repo exists on Github, you want it on your computer


$ git clone git@github.com:RBGKew/bioinfo-utils.git
            

Code exists on your computer, you want it on Github


$ git init
$ git remote add origin git@github.com:RBGKew/shiny-new-repository.git
$ git add .
$ git push -u origin master
            

File lifecycle

A file can exist in one of 4 states in git

  1. Untracked
  2. Modified
  3. Staged
  4. Committed
git status is your friend

Untracked

Create a new file for your bio and add it to git

$ vim docs/people/john-iacona.md
$ git add docs/people/john-iacona.md
          

Modified

Add your bio and see what has changed

$ vim docs/people/john-iacona.md
$ git diff
          

Staged

Once you are happy with your changes, add them to the staging area

$ git add docs/people/john-iacona.md
          

Committed

Finally, make an official snapshot of all staged changes

$ git commit -m "Super useful commit message"
          

Aside about commit messages

other obligatory xkcd...

Commit messages should document what you have done for others and your future-self

Think about what you've done


$ git log
        
If you are using my .gitconfig file, the following aliases can be useful.

$ git lol
$ git lola
      

Push it (real good)

Remote

Another copy of a repo. origin is the most common

$ git push -u origin HEAD
          

So fetch

If the remote repo has progressed beyond yours, you have to fetch changes and merge them with yours

$ git fetch
$ git merge origin/master
            

fetch vs. pull

pull tries to fetch and merge in one step.


$ git pull
            

Resources

http://rbgkew.github.io/doc/git.html