Show Menu
Cheatography

Git Cheat Sheet (DRAFT) by [deleted]

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Initia­lising a repository

Initia­lising a fresh repository
git init
Clone an existing repository
git clone <ur­l>
Clone an existing repository into a custom directory
git clone <ur­l> <di­rec­tor­y>
Clone an existing repository into current directory
git clone <ur­l> .

Managing branches

Get help
git branch -h
List local branches
git branch
List remote branches
git branch -r
List local and remote branches
git branch -a
Delete a local branch
git branch -d <br­anc­h>
Rename current branch
git branch -M <ne­w-n­ame>
Track a different remote branch
git branch -u <re­mot­e-b­ran­ch>
Find local branches that have been merged into a branch
git branch --merged <br­anc­h>
Find remote branches that have been merged into a branch
git branch -r --merged <br­anc­h>
Find all branches that have been merged into a branch
git branch -a --merged <br­anc­h>
 

Managing Remotes

List remotes
git remote -v
Add new remote
git remote add <na­me> <ur­l>
Change remote url
git remote set-url <na­me> <ur­l>
Change remote push url
git remote set-url --push <na­me> <ur­l>
Change remote pull url
git remote set-url --pull <na­me> <ur­l>

Push Changes

Push local changes
git push
Force push local changes
git push --force
Push to a different remote branch
git push <re­mot­e-b­ran­ch>
Push to a different remote branch and start tracking it
git push -u <re­mot­e-b­ran­ch>
Push to a remote branch that has a different name
git push <re­mot­e-b­ran­ch> <lo­cal­-br­anc­h>