Git Quick Sheet

Git Quick Sheet

First Steps

  • The first step for using a git is checkout the main branch

git clone git@tensho.pcbi.upenn.edu:<Repsitory Name>

  • After making changes, the code is checked in by:

git commit -am "<change message here (or whatever your message is note the "a" for add as well as the "m" for message )>"

git push <Repository Name>

Note that unlike svn, which has a single global copy and the local copy on your machine, git effectively has three copies of each branch - the files you see, the local repository that you commit to, and the remove repository (on sobolev) that you push to.

  • To sync to the latest version (always commit first, then pull):

git commit -a

git pull

After you have used git for a few days, you probably should set up your own branch. (See branches below.)

If you want to set up your own git backup

  • create a bare git directory wherever the repository is

mkdir foo.git; cd foo.git; git init --bare --shared=group;

remember the double dashes

  • populate it

git fetch <some local git repository> master:master

    • see below to make the local repo, then clone it back locally so you can edit it

git clone <Repsitory Name> (drop the .git suffix)

  • to create your own local git repository from data in foo.tar

tar -xvf foo.tar

cd foo

git init

git add .

git commit -m "import of foo source tree"

creating branches

  • if you want to make your own changes on your on branch, you can then

cd git_directory_name

  • into your new files, and type

git checkout -b <new branch name>

  • then
    • # move to your own branch to do some work

git checkout my_branch

    • # start working by getting all changes

git fetch origin

git merge origin/master

    • # also get something from lyle's branch

git merge origin/ungar

    • # do some stuff

git add file.txt

git commit -m "ENH: dollar dollar bill yo! "

git push origin my_branch

note that committing and pushing will only affect your branch, so you don't need to worry about messing other people up -- or being messed up by them.

if you want:

  • # also push to master if you think it's ready
  • # but be sure you are in sync first

git fetch origin

git merge origin/master

git push origin master

  • # or checkout master, merge in your stuff, and then push it

To learn about merging branches, see (e.g.) http://book.git-scm.com/3_basic_branching_and_merging.html

Fixing Things:

For fixing problems/mistakes look into the basic guide in http://ohshitgit.com/