Git Cheat sheet
Configure tooling
$ git config --global user.name "[name]"
Sets the name you want attached to your commit transactions
$ git config --global user.email "[email address]"
Sets the email you want attached to your commit transactions
$ git config --global color.ui auto
Enables helpful colorization of command line output
Branches
Branches are an important part of working with Git. Any commits you make will be made on the branch you are currently "checked out" to. Use git status
to see which branch that is.
$ git branch [branch-name]
$ git checkout [branch-name]
$ git merge [branch]
$ git branch -d [branch-name]
Create repositories
when starting with a new repository ,you need to do it once; either locally ,then push to github ,or by cloning an existing repository.
$ git init
$ git clone
Synchronize changes
Synchronize your local repository with the remote repository on GitHub.com
$ git fetch
$ git merge
$ git push
$ git pull
Details
Updates your current local working branch with all new
commits from the corresponding remote branch on GitHub.
`git pull` is a combination of `git fetch` and `git merge`
Make changes
Browse and inspect the evolution of project files
$ git log
$ git log --follow [file]
$ git diff [first-branch]...[second-branch]
$ git show [commit]
$ git add [file]
$ git commit -m "[descriptive message]"
Redo commits
Erase mistakes and craft replacement history
$ git reset [commit]
$ git reset --hard [commit]
CAUTION!
Changing history can have nasty side effects. If you need to change commits that exist on GitHub (the remote), proceed with caution. If you need help, reach out at github.community or contact support.