Git code examples
16 short, tested snippets. Pick one to see the code with notes, or search Zest for something specific, such as “git undo the last commit”.
- Undo the last commitgit reset --soft HEAD~1 # undo commit, keep changes staged
- Amend the last commitgit commit --amend -m "Better message"
- Stash changesgit stash push -m "wip"
- Create and switch branchesgit switch -c feature/login # create and switch
- Merge vs rebasegit switch feature
- Squash commitsgit rebase -i HEAD~3 # mark the later commits as "squash" or "fixup"
- Discard changes to a filegit restore file.txt # discard unstaged changes
- Pretty loggit log --oneline --graph --decorate --all
- Cherry-pick a commitgit switch release
- Set up a remote and pushgit remote add origin git@github.com:user/repo.git
- Force push safelygit push --force-with-lease
- Delete a remote branchgit push origin --delete feature/old
- Rename a branchgit branch -m new-name # current branch
- Resolve a merge conflict# edit the files, remove <<<<<<< ======= >>>>>>> markers, then:
- .gitignore basicsnode_modules/
- Tags and releasesgit tag v1.2.0