Skip to content

Instantly share code, notes, and snippets.

@omniosi
Last active August 10, 2018 17:59
Show Gist options
  • Save omniosi/107a7c08ced1541d7a0015ad615faf3b to your computer and use it in GitHub Desktop.
Save omniosi/107a7c08ced1541d7a0015ad615faf3b to your computer and use it in GitHub Desktop.
A list of useful terminal commands for Git
git commit file1 file2 file5 -m "commit message" ## add specific files and commit in one line
git commit -am "commit message" ## add all files and commt in one line - does not include new files
git push -u origin hotfix ## push a new branch to the remote
$ git push origin --delete <branch_name> ## delete remote branch
git checkout -b localbranchname origin/remotebrachname ## make local version of remote branch with tracking
git reset HEAD~ ## undo commit
git reset --hard HEAD^ ## undo local commit
git checkout -b newbranch SHAa9c146a09505837ec03b ## create a new branch from a previous commit
$ git tag -a v1.4 -m "my version 1.4" ## create a tag (https://git-scm.com/book/en/v2/Git-Basics-Tagging)
$ git checkout -b version2 v2.0.0 ## you can create a new branch at a specific tag with git checkout -b [branchname] [tagname]:
## Switched to a new branch 'version2'
git log --graph --decorate --oneline ## show chart of branching
git branch --merged master lists branches merged into master
git branch --merged lists branches merged into HEAD (i.e. tip of current branch)
git branch --no-merged lists branches that have not been merged
By default this applies to only the local branches. The -a flag will show both local and remote branches, and the -r flag shows only the remote branches.
git remote set-url origin <repo> ## change remote to new repo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment