Skip to content

Instantly share code, notes, and snippets.

@mitchwongho
Last active December 28, 2015 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitchwongho/b095f31fbce492ed6047 to your computer and use it in GitHub Desktop.
Save mitchwongho/b095f31fbce492ed6047 to your computer and use it in GitHub Desktop.
Handy Git commands
# Configuration
## disable mergetool backup files
$ git config --global mergetool.keepBackup false
# Branch
## Show Tracking Branch
$ git remote show origin
## Create a new branch
$ git checkout -b <branch> <remote>/<branch>
## Delete local branch
$ git branch -D <branch>
## Delete remote branch
$ git remote delete <branch>
## Push All tags to remote
$ git push origin --tags
## Rename local and remote branch
$ git branch -m <old-branch> <new-branch>
$ git push origin :<old-branch>
$ git push origin <new-branch>
# Add to tracking list
$ git add .
# Commit
$ git commit -a
## Commit with commit message
$ git commit -a -m "This is your commit message"
## Amend previous Commit
$ git commit -a --amend
# Fetch updates from remote
$ git remote update
# Merge with remote
$ git pull <remote> <branch> // e.g. $ git pull origin master
# TAGGING
## list Tags
$ git tag
## Add Tag
$ git tag -a <tag> -m <message/annotation>
## Show Tag Details
$ git show <tag>
## Delete local tag
$ git tag -d <tag>
## Apply Deleted Local tag
$ git push origin :refs/tags/<tag>
## Untrack files/dirs without deleting them
$ git rm --cached <file-to-untrack>
$ git rm --cached -r <dir-to-untrack/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment