git

I hate starting on new git projects. What is the right command again?


Create new local branch and create&push to remote

$ git branch -m <branch-name>
$ git push -u origin <branch-name>

Switch to the “master” branch:

$ git checkout master

Rename it to “main”:

$ git branch -m master main

Get the latest commits (and branches!) from the remote:

$ git fetch

Remove the existing tracking connection with “origin/master”:

$ git branch –unset-upstream

Create a new tracking connection with the new “origin/main” branch:

$ git branch -u origin/main

Discard change made to a branch

$ git reset --hard origin/main