Git Notes

I have recently taken the plunge into learning Git. These are my notes thus far. I know there are plenty of git write-ups out there on the web. I started this one mostly for myself as a quick cheat sheet. I figure it may be useful to someone so I am sharing it.

My typical git workflow

– git init (or clone)
– work on files on main branch
– git branch [newbranchname] (create a new branch for a new feature)
– git checkout branch (switch to that new branch)
– git merge [newbranchname] (merge new feature into main branch)
– git add . (or git add path/to/file(s))
– git commit (leave good notes)
– git pull [remote] [branch] (to sync with other devs)
– git push [remote] [branch] (send my local commits to other devs or repo server)

Some descriptions of other git commands

git init (initializes a directory as a new Git repository)
git clone [url] (copies an existing Git repository)
git status
git remote (list local "remote" aliases)
git remote add/rm [url] (creates a new alias)
git add (add changes; those could be in files or directory structure)
git add -u (adds unstaged changes including deletes not done with git rm)
git add -p (add changes per chunk in a file!)
gif diff (--cached for staged changes)
git commit (records a snapshot of the staging area)
git commit -m (specify a commit message on the command line)
git commit -a (skip the add step and do it automatically -a will not add new files)
git rm (delete a file, can be used to actually delete the file or after the fact to inform git of the action)
git rm --cached
(aka un-add/un-track)
git reset
(unstage changes that you have staged, opposite of git add)
git checkout --
..." to discard changes in working directory (???)
git update-index --assume-unchanged (ignore uncommitted changes in a file that is already tracked)
git pull/push (eg git push memoryties master)

My main source of information so far has been Git Reference.

Other resources
– http://nvie.com/posts/a-successful-git-branching-model/
– http://progit.org/book/
– git reset: http://progit.org/2011/07/11/reset.html