Git/GitHub: question about push and renaming branches

Background: experience with git - just a couple of weeks, mostly used it to manage projects on my local machine.

I have this remote repo.
Currently it has 1 branch called main.
Also I have corresponding local repo with branch master which is currently 1 commit ahead.
Here is some related info from bash:

UserName (master) freeCodeCampRegistrationForm
$ git log --oneline --graph
* 058bada (HEAD -> master) additional styling of submit button
* b44a026 (origin/master) set relative font-size for body, minsize for inputs
* 22e169e minsize for clickable inputs
* ec6e6a9 label and input adjustments
* 52dd5e2 unadjusted radio-buttons:solved, comments updated
* 0cc3817 refactor body and form size
*   6a8ee2c Merge remote-tracking branch 'origin/main'
|\
| * c7940f8 (origin/main) Initial commit
* 346fbb1 Update TODO-s
* 5822704 Adjust CSSBOX properties
$ git branch --all
* master
  remotes/origin/main
  remotes/origin/master
$ git remote -v
origin  https://github.com/AndreyDmitriev39r/freeCodeCampSurveyForm.git (fetch)
origin  https://github.com/AndreyDmitriev39r/freeCodeCampSurveyForm.git (push)

So if I will run ‘git push origin master’ rightnow, there will be two branches on remote repo: main and master(I am pretty sure that’s the case, I did such thing couple of times)

My question: what if I rename remote branch main and call it master first(using GitHub website), and then run ‘git push origin master’?

It will be 2 confusing branches with the same name master? Or something else?

I kind of want to structure this project to look like the other one:

UserName (initial-css) freeCodeCampTributePage
$ git log --oneline --graph -a
* 20f4a50 (HEAD -> initial-css) set font and color scheme
* d6b1440 normalize css
* 2222e67 (master) added references
* 8fa2e56 add subject info
* 40fe233 Chose subject of the page
* 5dfba9f (origin/master) created README file
* 9f80d93 TODO list
* 7bb5311 set meta tags
* b37c155 empty css
* 1e0c3bd Initial commit


UserName (initial-css) freeCodeCampTributePage
$ git branch
* initial-css
  master


UserName(initial-css) freeCodeCampTributePage
$ git branch --all
* initial-css
  master
  remotes/origin/master

Courtesy of @jwilkins.oboe : Git Rename Branch – How to Change a Local Branch Name

So rename your local branch: git branch -m master main. Your remote is already main so this should be all you need to do – the origin will still be pointing at exactly the same [correctly-named] branch

Edit: also, check that by default newly-initialised local repos use main – create an empty test directory and run git init – branch should be main on newer versions of git, so if it isn’t, I’d update git to newest (alternatively, if updating is an issue, you can just add a template for git init so that it always defaults to main [or trunk or my_great_new_name_for_the_main_branch or whatever you want :upside_down_face: ]) – loads of docs on this, here’s the first result I got from Google)

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.