Home > other >  How do I change the branch to commit (master > main) using git bash?
How do I change the branch to commit (master > main) using git bash?

Time:08-20

I'll summarize what happened to my computer.

What I wanted to do

To upload my local folder "freshman" to github repository named "Hanyang", I typed the commands below;

git init
git add freshman
git commit -m "blahblah"
git remote add origin https://github.com/myUsername/Hanyang.git
git push -u origin master
git push origin master

What happened

But I realized that the folder is well uploaded but inadvertently at the 'master' branch, while the default branch was 'main'.
So I manually deleted 'master' branch in github, got back to git bash then tried git add freshman again.

Did I have to do something to change the target branch (master > main) before merely trying git add freshman again?

Anyway unlike the first typing of the command, however, git bash says "nothing is added" even I checked it via git status - besides it says "my branch is up to date with 'origin/master' " which I already deleted as the image.

What I want to do now

In this situation, what should I do to upload my ''freshman'' folder to the main branch of the repository in github such that I can upload other folders (sophomore, etc.) after this?

CodePudding user response:

  • run git branch to see what branch you are on

  • to switch to main if not on main run git checkout main

  • if branch main doesn't exist locally you will need to run git branch main before checking it out

  • Then you can add your file, set the remote for the main branch, and push to origin main

CodePudding user response:

git branch -M main

for more information, look under Branching & Merging

https://github.com/joshnh/Git-Commands

  • Related