Skip to content

Instantly share code, notes, and snippets.

@franckweb
Last active April 12, 2023 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save franckweb/d28f68247b7935ff52174e23b89a508c to your computer and use it in GitHub Desktop.
Save franckweb/d28f68247b7935ff52174e23b89a508c to your computer and use it in GitHub Desktop.
Git commands
## zsh git aliases
https://github.com/ohmyzsh/ohmyzsh/wiki/Cheatsheet
## stash files for later
# add files to stash
git stash push -m "mystash"
# use specific stash
# use by number (n)
git stash apply stash@{n}
# use by name
git stash apply stash^{/my_stash_name}
# list
git stash list
# remove stash item
# remove latest stash item
git drop
# remove specific stash item
git stash drop stash@{n}
# show files of last stash
dit stash show -ph
## what changed in a file
git log --follow -p -- <filename>
##Fetch from remote branch to local branch
git fetch <remote> <remote_branch>:<local_branch>
git checkout <local_branch>
## UNDO GIT MERGE
# lists undo history for your repo, it references logs
git reflog
# resets to specific commit (eg. al commit 18)
git reset --hard HEAD@{18}
## RESET TO LAST PUSH
git checkout .
## UNSTAGE FILES
git reset HEAD -- .
## UNSTAGE FOLDER
git rm --cached -r myfolder
## UNDO COMMIT
# undo commit that was not pushed, while keeping the changes in the current branch
git reset HEAD~1 --soft
## ADD NEW CHANGES TO LAST COMMIT
git commit --amend --no-edit
## PRINT remotes fetch/push urls
git remote -v
## delete a pushed commit in remote and local
https://ncona.com/2011/07/how-to-delete-a-commit-in-git-local-and-remote/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment