Last active
August 29, 2015 14:05
-
-
Save squallstar/d182c5b0b2b7951c1e9d to your computer and use it in GitHub Desktop.
Some useful git commands
This file contains 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
# Fetch all the branches and their commits from the repo | |
git fetch origin | |
# Just fetch the branches from the repo | |
git fetch -p | |
# Display the remote branches | |
git branch -r | |
# Setting a local branch remote to the one on the origin | |
git branch -u origin/remote-branch local-branch | |
# Push a single branch | |
git push origin master | |
# Displays the remotes | |
git remote -v | |
# Adding a remote | |
git remote add myremote url | |
# Amending a remote url | |
git remote set-url myremote newurl | |
# Stash | |
git stash | |
git stash list | |
git stash pop | |
# Merging with fast-forward when you have unstaged changes | |
git stash && git pull && git stash pop | |
git commit -m 'my commit' | |
# Remove all untracked files | |
git clean -df | |
# Discard unstaged changes on the working tree | |
git checkout -- . | |
# Discard changes on a file | |
git checkout -- filename | |
# Display changes for a file between different commits | |
git diff firstcommit..secondcommit -- filename | |
# Revert a merge | |
git merge otherbranch | |
git reset --merge ORIG_HEAD | |
# Push a subdirectory as main directory | |
# Useful if you want to push on Heroku a subfolder as root | |
git subtree push --prefix dirname heroku master | |
# Discarding all changes and pulling from master | |
git reset --hard | |
git pull origin master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment