Skip to content

Instantly share code, notes, and snippets.

@joshuaadrian
Last active December 26, 2015 08:39
Show Gist options
  • Save joshuaadrian/7123900 to your computer and use it in GitHub Desktop.
Save joshuaadrian/7123900 to your computer and use it in GitHub Desktop.
## GLOBAL CONFIG ##
git config --global user.name "John Doe"
git config --global user.email "[email protected]"
## LOCAL CONFIG ##
git config user.email "[email protected]"
## COLOR CONFIG ##
git config --global color.ui true
# Alias git commands
git config --global alias.st status
# A little lookup for commands I use frequently
git reset --hard # removes staged and working directory changes
git clean -f -d # remove untracked files
# Commit all edited files and add a message
git commit -a -m "My commit"
# Add all modified, deleted, and new files
git add -A
# Perform a pull operation
git pull REMOTENAME BRANCHNAME
# Perform a push operation
git push REMOTENAME BRANCHNAME
# Prune all stale remote tracking branches
git remote prune REMOTENAME
# Create a branch and check it out at the same time
git checkout -b BRANCHNAME
# View branches
git branch -v
# Checkout a different branch
git checkout BRANCHNAME
# Checkout a remote branch
git checkout -b LOCALBRANCHNAME origin/REMOTEBRANCHNAME
# Merge the changes made in another branch in to the current branch
git merge BRANCHNAME
# Delete a local branch
git branch -d BRANCHNAME
# Delete a remote branch
git push origin :BRANCHNAME
# Delete a remote branch (sexier syntax)
git push origin --delete BRANCHNAME
# Throw away a messy merge (pre commit state)
git reset --hard HEAD
# Scrap uncommitted state and return the working tree to the last committed state
git reset --hard HEAD
# Delete the latest commit, and return to the one previous (one before HEAD)
git reset --hard HEAD~1
# Return a single file to it's last committed state
git checkout -- FILENAME
git checkout HEAD FILENAME
## LOG COMMANDS ##
git log
git log --pretty=oneline
git log --pretty=short
git log --
git log --pretty=oneline --abbrev-commit
## TRACKING FILES COMMANDS ##
# Stop a file being tracked (but do not delete it from the working directory, add to .gitignore etc after this)
git rm --cached <file/folder>
# Remove all current tracked files (but do not delete it from the working directory, add to .gitignore etc after this)
git rm -r --cached .
## STASH COMMANDS ##
# Stash uncommitted changes
git stash
# Stash uncommitted changes with comment
git stash save "Comment Here"
# Apply stashed changes somewhere
git stash apply
# List stashes
git stash list
# Delete top stash
git stash drop
# Delete all stashes
git stash clear
# Apply top stash and then delete it
git stash pop
# Create new branch from a stash
git stash branch new-branch-name stash@{0}
## REBASE COMMANDS ##
# Rebase current branch from master
git rebase master
## CHERRY PICK COMMANDS ##
# Cherry pick commit
git cherry-pick 53212e5
# Cherry pick with different commit message
git cherry-pick --edit 5321
# Cherry pick multiple commits and add to staging
git cherry-pick --no-commit 53212e5 55ae374
# Track which commit was cherry picked
git cherry-pick -x 5321
# Track who did the cherry pick
git cherry-pick --signoff 5321
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment