Skip to content

Instantly share code, notes, and snippets.

@wechulimaven
Forked from npearce/README.md
Created February 5, 2023 14:45
Show Gist options
  • Save wechulimaven/b02f687ff25fd1a6551f472009bbf320 to your computer and use it in GitHub Desktop.
Save wechulimaven/b02f687ff25fd1a6551f472009bbf320 to your computer and use it in GitHub Desktop.
Useful git commands

Useful git commands

This gist is for collecting git commands I don't use often enough to remember, but probably waste too much time trying to find when I need them.

Edit Last Commit Message - NOT PUSHED

git commit --amend

Edit Last Commit Message - PUSHED

git commit --amend

git push --force <branch>

Remove a file from staging

git reset filename.txt

Rename Local

git checkout <branch_to_rename>

git branch -m <new_name>

Push to Remote

NOTE This is effectively a new remote branch

git push origin -u <new_name>

Delete Old Remote

git push origin --delete <old_name>

rolling back to a previous, specific commit:

  1. Fund the for the commit you want to return using:

git log

  1. Reset local HEAD to that point:

git reset --hard <commit-id>

  1. Push this to remote origin:

git push origin -f

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