Skip to content

Instantly share code, notes, and snippets.

@StuartsHome
Last active April 8, 2021 14:08
Show Gist options
  • Select an option

  • Save StuartsHome/a4cbec6f42502c0730c01ca9a23ea033 to your computer and use it in GitHub Desktop.

Select an option

Save StuartsHome/a4cbec6f42502c0730c01ca9a23ea033 to your computer and use it in GitHub Desktop.
Useful commands that are not related to workflow, terminal-cheat sheet, etc.
# Workflow - work on coworker's branch
1. `fetch` all remote branches
- $ git fetch origin
2. Check branch available for checkout
- $ git branch -a
3. Make local copy of branch
- $ git checkout -b <name-your-branch> origin/<name-of-remote-branch>
Remove file from GitHub - remove from index:
- $ git rm -- cached <filename>
Create new branch that tracks remote branch:
- $ git branch -a
- $ git branch --track branch-name origin/branch-name
View tracking branches; shows all branches (local and remote tracking):
- $ git branch -a
Git rename branch:
- $ git branch -M main
- $ git branch <oldbranchname> <newbranchname>
Push to a branch and track
- $ git push -u <branchname>
Set existing branch to track:
- $ git branch --set-upstream-to origin/<branch>
- $ git branch -u origin/<branchname>
Search files for <text>:
- $ git grep <text>
# Remotes
Display remotes and URLs:
- $ git remote -v
Show remote information:
- $ git remote show <remote>
- e.g. $ git remote show origin
# Branches
Display Last branch commit:
- $ git branch -v
# General
To see git merge conflicts:
- $ git status
To use graphical tool to resolve merge conflicts:
- $ git mergetool
Clone a single branch - fetch only this branch:
- $ git clone --single-branch --branch <branchname> <remote-repo>
Clone a single branch - fetch all branches - checkout out one:
- $ git clone --branch <branchname> url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment