Git/hacks: Difference between revisions

No edit summary
Line 118: Line 118:


Credit: there's a clear explanation at https://www.git-tower.com/learn/git/faq/undo-last-commit
Credit: there's a clear explanation at https://www.git-tower.com/learn/git/faq/undo-last-commit
== Throw away your local branch ==
You've probably encountered some advice to
<code>git reset --hard origin/main</code> to totally throw away your local working copy so you can pull the remote code.
That works just fine, and <code>git reset --hard '@{u}'</code> works even better because <code>@{u}</code> stands for the remote tracking branch for whatever branch you're on in your local repo.<ref>When you have a tracking branch set up, you can reference its upstream branch with the @{upstream} or @{u} shorthand. So if you’re on the main branch and it’s tracking origin/main, you can say something like git merge @{u} instead of git merge origin/main if you wish. - source: https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches</ref> You do not need the literal quotes if you are not using Windows Powershell or csh.


==Good and Consistent commit messages==
==Good and Consistent commit messages==