Skip to content

Instantly share code, notes, and snippets.

@alperozaydin
Last active February 13, 2020 16:26
Show Gist options
  • Save alperozaydin/60298ca433303c6c3852e2d783f86f85 to your computer and use it in GitHub Desktop.
Save alperozaydin/60298ca433303c6c3852e2d783f86f85 to your computer and use it in GitHub Desktop.
git cheat sheet
# List all branches
$ git branch -a
# Switch to another branch
$ git checkout <branch_name>
# Which branch I am at
$ git branch
# Revert Changes to File
$ git checkout -- <file>
# Revert File to Previous Commit
$ git checkout <commit_hash> -- <file>
# Logs and lits all commits
$ git log
# Discard local changes
$ git reset --hard
# Remove a file after git add .
$ git reset -- filename.txt
# Update latest commit even it is pushed already
git commit --amend #Then change the first line with the commit message you would like to change
git push --force
# if there is multiple message follow the link
https://linuxize.com/post/change-git-commit-message/
# Somehow u messed up stash and getting "already exists, no checkout" error
git stash show --patch | patch -p1
git stash -a
git stash apply <ur stash>
# You need to stash changes and load them again bc of git pull or smth else. save and pop. pop removes the stash from the stash list.
git stash save
git pull (or any other command you would like to do)
git stash pop
# How to reabase
git rebase -i HEAD~<number of commits>
# then make changes pick, fixup, squash. it will bring another screen
git push -f
# revese back commits and changes on the repositoty
git log # find the commit hash that you would like to go back
git reset --hard <commit hash>
git push -f
# you messed up. you made changes then commited but didnt push and applied hard reset. Still you can get files back
git reset HEAD@{1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment