Last active
September 1, 2015 18:26
-
-
Save hattmarris/b294666d5159c18111e1 to your computer and use it in GitHub Desktop.
Git Commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create new branch | |
git checkout -b <branchname> | |
# Push branch to remote | |
git push -u origin <branchname> | |
# Merge branch back in | |
git checkout master | |
git merge <branchname> | |
# Delete branch locally | |
git branch -d <branchname> | |
# Delete branch on remote | |
git push origin --delete <branchname> | |
# Setting your branch to exactly match the remote branch can be done in two steps: | |
git fetch origin | |
git reset --hard origin/master | |
# If you want to save your current branch's state before doing this (just in case), you can do: | |
git commit -a -m "Saving my work, just in case" | |
git branch my-saved-work | |
# Will remove untracked files, including directories (-d) and files ignored by git (-x). | |
git clean -d -x -f | |
# Replace the -f argument with -n to perform a dry-run | |
git clean -d -x -n | |
# Or -i for interactive mode and it will tell you what will be removed. | |
git clean -d -x -i | |
# Git log - Shows the commit logs. | |
# Raw output from commit log file | |
git log --graph --decorate --all --pretty=raw | |
# Keep commit info printed on one line | |
git log --graph --decorate --all --oneline | |
# Git rebase | |
# A---B---C topic | |
# / | |
# D---E---F---G master | |
git rebase master # shorthand | |
git rebase master topic | |
# result | |
# A'--B'--C' topic | |
# / | |
# D---E---F---G master | |
# Reset a mistaken rebase (immediately after rebase - otherwise ORIG_HEAD might be different snapshot) | |
git reset --hard ORIG_HEAD | |
# Git Fetch remote branch (create or update locally as branch-loc) | |
# http://git-scm.com/docs/git-fetch#_examples | |
git fetch origin branch:branch-loc | |
# Peek at a remote’s branch, without configuring the remote in your local repository: | |
git fetch git://git.kernel.org/pub/scm/git/git.git maint | |
git log FETCH_HEAD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment