These are my personal notes about git which might help others, most are self explanatory.
General
To create a new git repo in the current directory:
git init
Check the status of the repository, helpful for seeing what has changed:
git status
See last five commits:
git log
Add a new file to the repo:
git add <filename>
Show changes to a file between commits:
git diff <filename>
Commit changes to staging area:
git commit -m <message>
See latest commit:
git show HEAD
Discard changes to file in working directory:
git checkout HEAD <filename>
Unstage changes to file in working directory:
git reset HEAD <filename>
Revert to previous commit identified by the SHA:
git reset <sha>
List local branches:
git branch
Create local copy of remote repo:
git clone <remote repo url>
List remote repos:
git remote -v
Pull changes from remote repo into local copy:
git fetch
Merge remote origin into local branch:
git merge origin/master
Push branch to remote origin:
git push origin <branch name>
List modified files:
git diff --name-only
Everyday Workflow for Branching
Create a new branch:
git branch <new branch name>
Checkout the new branch:
git checkout <new branch name>
Commit changes to the new branch:
git commit -a -m <message>
Switch back to master:
git checkout master
Merge branch to master:
git merge <new branch name> master
Delete branch:
git branch -d <new branch name>
Push changes to origin:
git push origin
Tagging (optional)
Add a tag to the branch:
git tag -a <tag name> -m "message"
Push tag to remote repo:
git push origin <tag name>