1

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?

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • 2
    Does this answer your question? [How do I rename my Git 'master' branch to 'release'?](https://stackoverflow.com/questions/8762601/how-do-i-rename-my-git-master-branch-to-release) – tripleee Aug 19 '22 at 18:06

2 Answers2

0
  • 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

micah
  • 838
  • 7
  • 21
  • When I run ```git branch```, the result is main in green color and another trash one that I created minutes ago by mistake. Does this mean that I'm already on main? – Ahn Jun-Yeong Aug 19 '22 at 18:15
  • @AhnJun-Yeong yeah that means you're on main, so all you'll have to do is push to `origin main` – micah Aug 19 '22 at 18:19
  • but still ```git commit``` doesn't work with the message "Your branch is up to date with 'origin/master' and 'nothing added to commit". Of course I tried directly ```git push origin main``` but only to be rejected. – Ahn Jun-Yeong Aug 19 '22 at 18:24
  • @AhnJun-Yeong idk if this is a great solution, but it should work, I'd SAVE FRESHMEN SOMEWHERE then run `git reset --hard origin main`, add freshmen back if removed, run git add freshmen, git commit, git push – micah Aug 19 '22 at 18:29
  • 1
    okay that must be detour but i think it must work as well!! Thanks – Ahn Jun-Yeong Aug 19 '22 at 18:44
0
git branch -M main

For more information, look under Branching & Merging.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77