Quick Git – Branch Rename and Remotes


Updated Aug 12th, 2021

Branch Rename (from master to main)

git branch -m master main

You will need to change the remote repo as well but it is not as simple. You need to create a new main branch from the master branch and, when that is confirmed working, then delete the master branch.

git push -u origin main
git push origin --delete master

Check git tower for more details.

Update Remote After Clone

git remote    // origin (this could be anything - may see upstream or other)

git remote -v     // wherever you grabbed your clone from

git remote set-url     // needs two things: 1.) name (leave as origin) and 2.) updated url

Deleting .git Folder to Start Over

The .git folder is hidden and to see hidden folders in the windows command line:

dir /a

If you try and delete a non-empty directory you will get a “not an empty directory” message so use:

rmdir .git /s

Note: the s in /s is not case sensitive

Another note: I love the “gittower.com” ui.

Add a Remote When Starting Fresh

git remote add origin yourRemoteURLHere.git

Note: origin can be named anything, it doesn’t have to be origin although that is the convention

And Just Because I Always Botch This Command…

git commit --amend -m"New Commit Message for Most Recent Commit Here"