Skip to content

Instantly share code, notes, and snippets.

@melanierichards
Last active August 28, 2022 17:32
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 melanierichards/98d2db0692d9ea0a1e404b5b6f156b1c to your computer and use it in GitHub Desktop.
Save melanierichards/98d2db0692d9ea0a1e404b5b6f156b1c to your computer and use it in GitHub Desktop.
Git commands

Git commands

That which I often forget and frequently use. Git reference

History

Purpose Command
Rebase git rebase -i HEAD~{n}, enter into editing mode in vim and save, git push --f
Reset to a previous commit after pushing changes git reset --hard {commit}, git push -f

Remotes

Purpose Command
Add a new remote git remote add {name} {url}
Rename a remote git remote rename {oldname} {newname}
Delete a remote git remote rm {name}
Set up a local branch to track an existing remote branch git branch --track {branchname} {remotename}/{branchname}
Add a remote branch for a new local branch git push --set-upstream {remotename} {branchname}
Change remote branch git push --set-upstream-to {remotename} {branchname}
Stop tracking a remote branch git branch --unset-upstream

Misc

Purpose Command
Delete all branches except main and some other branch git branch | grep -v " main$" | grep -v " other-branch$" | xargs git branch -D

Git reference

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