Skip to content

Instantly share code, notes, and snippets.

@willamesoares
Last active April 14, 2018 23:28
Show Gist options
  • Save willamesoares/4da12eef9a55fbdfbdd3b9af96396d97 to your computer and use it in GitHub Desktop.
Save willamesoares/4da12eef9a55fbdfbdd3b9af96396d97 to your computer and use it in GitHub Desktop.

Git Cheat Sheet

Unstage tracked files

$ git reset HEAD [file]

Undo last commit (keeping changes)

$ git reset --soft HEAD^

Resolve conflicts

  1. Go to the branch you want to merge with (master, for instance)
$ git checkout master
  1. Pull changes from that branch
$ git pull
  1. Go to the branch with conflicts and rebase it with master
$ git checkout [branch] && git rebase master
  1. Resolve any conflict that shows up and add changes
$ git add .
  1. Continue rebasing your branch
$ git rebase --continue
  1. Repeat steps until you have no more files with conflicts and the rebase is finished.

Delete specified branch

$ git branch -d [branch-name]

Rename current branch

$ git branch -m [new-branch-name]

Check list of commits (oneline mode)

$ git log --oneline

Apply and remove changes stashed

$ git stash pop

Include changes on last commit

$ git commit --amend

Save git credentials

$ git config credential.helper store

Reset local branch with remote branch

git reset --hard origin/master

Update local branch with remote

git fetch && git rebase origin/master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment