Skip to content

Instantly share code, notes, and snippets.

@Pestov
Last active September 20, 2022 18:06
Show Gist options
  • Save Pestov/7122342 to your computer and use it in GitHub Desktop.
Save Pestov/7122342 to your computer and use it in GitHub Desktop.
Git Commands
$ git reset --hard HEAD~3 <1>
git remote prune origin - удалить все ветки
git commit --amend -m - Edit commit message
git reset HEAD^ # remove commit locally
git push origin +HEAD # force-push the new HEAD commit
git reset --hard <commit-hash>
git push -f origin master
git push origin +HEAD:demo
//Force PULL
git fetch --all
git reset --hard origin/master
git rev-parse --abbrev-ref HEAD
That will display the current branch
Undo a commit and redo
$ git commit ... (1)
$ git reset --soft 'HEAD^' (2)
$ edit (3)
$ git add .... (4)
$ git commit -c ORIG_HEAD (5)
This is what you want to undo
This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message, or both. Leaves working tree as it was before "reset". (The quotes may or may not be required in your shell)
Make corrections to working tree files.
Stage changes for commit.
"reset" copies the old head to .git/ORIG_HEAD; redo the commit by starting with its log message. If you do not need to edit the message further, you can give -C option instead.
git branch -m old_name new_name
git push <REMOTENAME> :<BRANCHNAME> // delete remote branch
git reset HEAD^ # remove commit locally
git push origin +HEAD # force-push the new HEAD commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment