Home > Blockchain >  Github how to merge branch to main?
Github how to merge branch to main?

Time:07-09

I have main and branch myStudy.

And I want to merge myStudy to main. But I keep facing this issue message.

On branch main
Your branch is ahead of 'origin/main' by 4 commits.
  (use "git push" to publish your local commits)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)
        modified:   Modern-JavaScript-Deep-Dive (untracked content)

In order to reflect these 4 commits, I tried to do below:

(1) checkout myStudy (2) git add . (3) git commit -m "~" (4) git push origin main

But when i do (3) commit, it throws same error.

On branch myStudy
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)
        modified:   Modern-JavaScript-Deep-Dive (untracked content)

no changes added to commit (use "git add" and/or "git commit -a")

How to fix it?

CodePudding user response:

The fact your local branch main is ahead of 'origin/main' by 4 commits means you don't have anything to do to "reflect those 4 commits": they are already there:

git switch main
git merge myStudy
git push

Regarding

(commit or discard the untracked or modified content in submodules)
        modified:   Modern-JavaScript-Deep-Dive (untracked content)

That means you have untracked content in a subfolder Modern-JavaScript-Deep-Dive declared a submodule:

cd Modern-JavaScript-Deep-Dive
git status # check if you are on a branch
git branch -avv
git switch main # if you were not on a branch but there is an origin/main
git add .
git commit -m "Add new content to Modern-JavaScript-Deep-Dive"
              (replace it with a more meaningful comment)
git push
cd ..
git add . # to record the new submodule tree/SHA1
git commit -m "Update Modern-JavaScript-Deep-Dive submodule"
git push

CodePudding user response:

git fetch
git checkout main 
git pull 
git merge <your_branch_name>
git push

fetch branch (if doesn't exists in your local),then switch to the merging branch

  •  Tags:  
  • git
  • Related