|
# *************************** |
|
# Configuration |
|
# *************************** |
|
|
|
git config --global user.name "<your name>" |
|
git config --global user.email <[email protected]> |
|
git config --global core.editor "<command line program that will open your editor, e.g. 'vim'>" |
|
|
|
# These settings should end up in a .gitconfig file in your user folder |
|
|
|
# *************************** |
|
# Commands |
|
# *************************** |
|
|
|
# Switch to a branch |
|
git checkout <branch> |
|
|
|
# Create a new branch |
|
git checkout -b <branch> |
|
|
|
# Check which branch you are currently on |
|
git branch |
|
|
|
# See what files have been changed since the last commit, and which ones are staged for commit |
|
git status |
|
|
|
# Add a file to the staging ground for the next commit |
|
# e.g. `git add app test` (adds all changed files in app/ and test/ to your next commit) |
|
git add <file or directory> |
|
|
|
# Add specific changes to staging area, change by change |
|
git add -p |
|
|
|
# Create a commit |
|
git commit -m "Message here" |
|
|
|
# Or if you want to edit the message in your favorite editor, you can do: |
|
git commit |
|
|
|
# Reset a file to its state from the previous commit |
|
git checkout <file> |
|
|
|
# See commit history. There are also prettier ways to do this. See recommendations below. |
|
git log |
|
|
|
# Merge branches |
|
git checkout <destination-branch-name> |
|
git pull # make sure you have the latest changes |
|
git merge <target-branch-name> |
|
|
|
# Conflict resolution: |
|
# 1. Fix conflicts in files that are listed in git |
|
# 2. Add file to staging |
|
git add <fixed-file> |
|
# 3. Make a new commit |
|
|
|
# Rebase branch: |
|
# See http://www.git-scm.com/book/en/v2/Git-Branching-Rebasing |
|
git rebase <target-branch> |
|
|
|
# Push branch to remote: |
|
git push <remote> <branch> # The main code hosting remote is always called "origin" |
|
|
|
# Push everything up, assuming "origin" remote exists |
|
git push --all |
|
|
|
# Create a "tag", a snapshot of the codebase. Useful for versions, etc |
|
git checkout <branch-you-want-to-tag> |
|
git tag <name> # e.g. "git tag version2.0" |
|
git push <remote> <tag-name> # git push origin version2.0 |