That which I often forget and frequently use. Git reference
| 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 |
| 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 |
| Purpose | Command |
|---|---|
Delete all branches except main and some other branch |
git branch | grep -v " main$" | grep -v " other-branch$" | xargs git branch -D |