Skip to content

Instantly share code, notes, and snippets.

@ricardoaugusto
Last active April 14, 2024 20:14
Show Gist options
  • Save ricardoaugusto/d76a5d3de35fac763220546e1d01c929 to your computer and use it in GitHub Desktop.
Save ricardoaugusto/d76a5d3de35fac763220546e1d01c929 to your computer and use it in GitHub Desktop.
Git commands (I keep forgetting)
# REMOTE
git remote -v # to list the remotes
git remote set-url origin new-remote-url # change the url
git remote rename origin new-remote-name # change the remote name
# DELETE BRANCH
git branch -D some-branch # local
git push origin --delete remote_branch_name # remote
# RENAME BRANCH
git branch -m master main # to rename
git checkout main
git push origin main
git branch -u origin/main
# REVERT "Update branch" on GitHub
git push origin HEAD --force
# UNTRACK FILES
git rm --cached filename.ext
# REVERT A COMMIT
git reset --hard <hash>
git push origin branch --force
# REBASE FROM MAIN
git checkout main
git pull origin main
git checkout some-branch
git rebase master
git push origin HEAD --force-with-lease
# RENAME BRANCH LOCAL AND PUSH TO REMOTE
git checkout <local-branch>
git branch -m <new-branch-name>
git push --force origin <new-branch-name>
git branch --unset-upstream # in case remote branch is gone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment