Skip to content

Instantly share code, notes, and snippets.

@KarllosSouza
Last active February 19, 2019 14:16
Show Gist options
  • Save KarllosSouza/63997b0a1991c8f15824 to your computer and use it in GitHub Desktop.
Save KarllosSouza/63997b0a1991c8f15824 to your computer and use it in GitHub Desktop.

Git Commands

Rename a local branch: git branch -m branch-name

Delete a local branch: git branch -d branch-name

Delete a remote branch: git branch -dr origin/branch-name

Remove local branches which are no longer available on the remote: git fetch -p

Undo non-pushed commits: git reset origin/master

Undo the last commit: git reset HEAD~ --hard

Undo the last commit, but leave the changes available: git reset HEAD~ --soft

Revert file to origin branch's version: git checkout origin/master file_name

Sync local branch with remote branch: git fetch --all && git reset --hard origin/master

Change message of last commit: git commit --amend -m "New message"

Visual representation of the branch merging into master: git log --oneline --graph

View unpushed git commits: git log origin..

See previous git commands executed: history | grep git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment