Skip to content

Instantly share code, notes, and snippets.

@gabrysiak
Last active September 18, 2016 04:09
Show Gist options
  • Save gabrysiak/d80d838df9ba63336442 to your computer and use it in GitHub Desktop.
Save gabrysiak/d80d838df9ba63336442 to your computer and use it in GitHub Desktop.
Git Commands Cheatsheet

Git Commands Cheatsheet

A list of commonly used GIT commands.

Create


Clone an existing repo

git clone https://github.com/user/repo.git

Create a new local repo

git init

Local Changes


Status of your working directory

git status

Changes to tracked files

git diff

Add ALL files to next commit

git add .

Add single file to next commit

git add -p somefile.txt

Commit with message

git commit -m 'Your message here'

Add & Commit & Push in single command

git add . && git commit -am. && git push

Commit without commit message (hacky way does not add a COMMIT MESSAGE)

git commit -am.

Add ALL deleted files to next commit

git add -u .

Add single deleted file to next commit

git add -u somefile.txt

Undo Commands


Show all commits starting with newest

git log

Show changes over time for specific file

git log -p somefile.txt

Check who changed what and when in file

git blame somefile.txt

Branches & Tags


List all branches

git branch

Switch HEAD branch

git checkout <branch>

Create new branch based on current HEAD

git branch <new-branch>

Create new tracking branch based on a remote branch

git branch --track <new-branch> <remote-branch>

Delete local branch

git branch -d <branch>

Add tag to current commit

git tag <tag-name>

Update & Publish


List all remotes

git remote -v

Show remote information

git remove show <remote>

Add new remote repo

git remote add <remote> <url>
git remote add origin https://github.com/user/repo.git

Download all changes from but dont integrate into HEAD

git fetch <remote>

Download all changes from and directly merge into HEAD

git pull <remote> <branch>
git pull origin

Publish local changes to remote

git push <remote> <branch>

Delete a branch on the remote

git push <remote> :<branch>

Publish Tags

git push --tags

Merge & Rebase


Merge into HEAD

git merge <branch>

Rebase current HEAD onto

git rebase <branch>

Abort a rebase

git rebase --abort

Continue a rebase after resolving conflicts

git rebase --continue

Solve conflicts via merge tool

git mergetool

Undo Commands


Discard local changes in working directory

git reset --hard HEAD

Discard local changes in specific file

git checkout HEAD somefile.txt

Revert a commit by producing

git revert <commit#>

Reset your HEAD pointer to previous commit and discard changes since then

git reset --hard <commit#>

Reset your HEAD pointer to previous commit and preserve all changes as unstaged changes

git reset <commit#>

Reset your HEAD pointer to previous commit and preserve uncommited local changes

git reset --keep <commit#>

Ignore changes in tracked files

git update-index --assume-unchanged somefile.txt

Track files that are being ignored (undo previous command)

git update-index --no-assume-unchanged somefile.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment