Home > Software engineering >  Do we have to merge branches separately in VS Code and in GitHub?
Do we have to merge branches separately in VS Code and in GitHub?

Time:11-30

I am working on my first major project.

  1. I made a new branch (left-nav) using GitHub and worked on it in VS Code.
  2. As my work is completed in that particular branch (left-nav) I merged it to the master branch using GitHub.
  3. But after merging branch(left-nav) with the master branch in GitHub, when I opened VS Code with the master branch as an active branch, the code of branch (left-nav) was not merged in VS Code whereas when I see the same file in GitHub it has all the code in it.

Do I have to merge code separately in GitHub as well as in VS Code, or I am getting it wrong somewhere?

CodePudding user response:

You need to pull the new changes from GitHub using git pull origin master

Note:

I would advise you to merge the branches locally & then pushing your changes to GitHub. This will be helpful in case something breaks.

CodePudding user response:

Do I have to merge code separately in GitHub as well as in VS Code, or I am getting it wrong somewhere?

No, you don't need to merge separately; you are just missing a step.

Basically your local copy of the repo is out of date. If you perform a git fetch to update your copy of what's on GitHub, and then take a look at origin/master you will see your changes there (this assumes your remote is called "origin", which is the default).

If you also want to see those changes on your local copy of master, you need to update that copy of master with what's in origin, and one way to do that is to checkout master and merge the latest commits from origin/master into it. (Note the command pull will do a fetch and merge in a single command.)

This is slightly more advanced, but once you get the hang of dealing with origin, you don't really need to keep a local copy of master anymore since you can already view what you wish to see using origin/master instead. Coincidentally, I just answered another question today which explains this concept in more detail, which is definitely relevant to your specific question too.

  • Related