Revisiting Git thanks to Scott Chacon and O’Reilly

By | September 11, 2009

I just watched Scott Chacon’s excellent video introduction to basic Git functionality: http://video.linuxfoundation.org/video/1516.  The audio was a bit tough to take, but it was free, and the content was so good that the audio didn’t bother me too much.  There are many excellent resources on git-scm.org, home of Git, but for whatever reason I didn’t find anything as straightforward as what Scott has done.  Admittedly, I probably didn’t try to hard, rather I just dove in and then became confused.  The video introduces a bunch of concepts along with the commands, and that helped a lot in terms of orienatation to functionality.

To help me in the future, I made a list of the various commands I think I will be using once I get more into modifying the code of my projects that are now in repositories.  Sorry for the brief explanations but perhaps the list can be useful to you as well (and I’m nervous about just leaving it on my hard drive and then forgetting where I put it, not that that ever happens to me !).

git clone <git repo> – creates a git repo in current directory from the git repo id. If you clone, creates a remote called origin by default
git init – creates a new git repo in the current directory

git branch <new branch>
git checkout <branch> – switch to branch
git checkout -b <branch> – creates new branch and switches to it
git branch -v – shows last commit on each branch

gitk – visually shows branches
gitk –all

git commit -am ‘commit message here’ – does staging and committing in one shot
git add file – adds file to repo, or stages it if already there

git status – shows status of current repo
git log – shows log of commits
git diff – what changed between last commit and current
git add –p

git config –global <x> (for changing global values)
git config –list (for listing environment values)

git merge <branch> – Merges branch with current branch
git branch -d <branch> – removes a branch

git branch <new branch> <old branch> – creates a branch from old branch. You can use id from git log as old branch to identify branch point

git remote add <remote name> <remote code> – specifies a new remote location given by name and code
git push <remote name> <branch name> – pushes the branch to the remote location
git remote -v – lists the remotes for the repo
git fetch <origin> – gets the repo from the origin (remote) as a local branch (not override, like pull)

git log <branch> –not <other branch> – show a log of what is in branch but not in other branch
git log –stat <branch> –not <other branch> – shows log of specific lines in changes

git blame – lets you see who modified a line last

git bisect – awesome tool to help figure out where error introduced
git bisect good <commit point sha> – that point it was good
git bisect reset – resets to where you were before bisect process
git bisect bad – current point was bad
git bisect start – starts bisect by checking out middle commit, which you can test and then say good or bad

[Update: this wasn’t part of the video, but a very useful command for people like me who rush to commit only after realizing I forgot to add a new file: git reset –soft HEAD^ – undoes the most recent commit, ready for me to add the right files and re-commit]

I also found this great resource from github.com: http://learn.github.com/

Category: Git

Leave a Reply

Your email address will not be published. Required fields are marked *