Git, used along with Github, is a great way to manage the work of writing code. It allows you to collaborate easily on even very large-scale projects, and provides a great place to quickly host code for sharing it with others. If you're going to write significant amounts of code, I highly recommend using it.
Below is a list of commented Git commands in rough order of probable workflow. I use this as a quick reference for using Git. If you happen to want to add comments or questions, I'm making this blog entry into a Github Gist. You can view it here.
git init #start a repo
git add mynewfile.py #track a file
git rm --cached myoldfile.py #untrack a file
git commit -m 'my commit message' #commit changes with a note
git push -u origin master # push to the 'master' branch on the 'origin' remote
git branch mynewbranch #create a new branch
git branch # see branches
git checkout mynewbranch #switch branches
git commit -a -m 'committing stuff' #commit all changes with note
git checkout master #switch to branch named 'master'
git log #see git history
git help #get help with git
git help [command] #get help with command
git add --all # add all updates
A whole daily workflow
git checkout master #go to master branch
git pull origin master # pull all updates
git checkout -b mylittlebranch # start a branch for a new feature
# do a whole bunch of work
git status #review a list of the files changed
git add mynewfile.py #track new files or folders
git diff # review differences
git diff | gitx # better, install gitx
# now, save the changes with a note about what you did
git commit -a -m 'my detailed commit message'
# OPTIONAL, sharing this branch on github:
# go create a repository on github 'github.com/username/repo'
# then add that repository as a remote called 'origin'
git remote add origin [email protected]:username/repo.git
git checkout mylittlebranch #move to new branch
git push origin mylittlebranch #push new branch to github
# then someone else can do the following:
git remote add origin [email protected]:username/repo.git
git fetch #get the stuff from the repo
git branch -a #lists all branches including remotes
# now for them to work on the same new branch ...
git checkout -b mylittlebranch origin/mylittlebranch
# then they make their changes
git add
git commit
git push origin mylittlebranch
# now, continuing from above, to merge a new branch back in
git checkout master #move back to master branch
git merge mylittlebranch #merge the new branch in like this, or ...
git merge --squash mylittlebranch #combine into one commit
# resolving merge conflicts
# look at conflicted file, edit to satisfaction
git add conflictedfile # restages the file
git commit 'ready for butter-smooth merge'
git push # all done!
# done with a branch? delete it
git branch -d mylittlebranch
Tags
git tag TAG_NAME
git tag release/1.1
git push origin TAG_NAME # push to remote
Remotes
# add a remote
git remote add mynewremote [email protected]:myusername/myrepo.git
# show remotes
git remote
# push to the remote
git push mynewremote myremotebranch
# delete a remote
git remote rm mynewremote
###More useful links: