Too nervous to merge branches

I am using Github Desktop for my project. These are the steps so far:

  1. Created Master - added a bunch of code.
  2. Created Branch1 - added a bunch of code; deployed this to Github Pages
  3. Created Branch2 - added another feature
  4. Now I want to update/overwrite Branch1 code with Branch2 code
  5. Then re-deploy Branch1 (which will now have all the new code from Branch2) to Github Pages

The only way Github Pages will publish more than one repo is if you deploy repo from Branch1 and not Master. But I do want to keep Branch1 and Master in sync for best practice. So final step (or maybe between step 4 and 5 above) would be:

  1. Update/overwrite Master code with Branch1 or Branch2 code (as they should be the same at this point). Deploy to Github so remote Master is same as local Master.
  2. Finally, I want to delete Branch2 and have the Branch1 branch be the “active” branch and the project be ready for another feature (with a whole other branch) whenever I am ready to start that.

I reviewed the steps here, but I was getting a little lost figuring out which Branch was being merged into and which Branch was merging.

My nightmare scenario is that I do the opposite Branch merge of what I meant to and wipe out several days of (amazing) work.

This is what I think I need to do for each step; can someone confirm??

  1. Done
  2. Done
  3. Done
  4. If Branch1 === gh-pages and Branch2 === gh-pages1, what do I select as Current Branch and what do I select for Choose A Branch to merge into gh-pages1:

Many thanks!!

You checkout (have active or selected) the branch you want to merge into. If I understand what you are asking, you would be on the gh-pages branch and then merge gh-pages1 into it.

I don’t really use GitHub Desktop but the UI is pretty clear about what you are doing. It writes it out “Merge BranchName into BranchName”

I’d suggest doing a practice run.

  1. Make a new repo, add a text file with the text “Initial code”. Commit the change.

  2. Make a new branch, base it on Master and call it feature1. Switch to it and open the text file. Now add the text “Feature 1 code”. Commit the change.

  3. Make a new branch, base it on feature1 and call it feature2. Switch to it and open the text file. Now add the text “Feature 2 code”. Commit the change.

  4. Switch back to the feature1 branch. From the Branch menu select “Merge into current branch”. From the modal that opens select the feature2 branch.

  5. Stay on the feature1 branch and open the text file, it should now contain all three commits.

Initial code
Feature 1 code
Feature 2 code

Also, if you are really worried you can make a backup branch or even backup the project folder itself before making any changes.


OK. that all makes sense. I will probably just back up my code in another folder on cloud then do the merge. Thanks!

Side bar: I started digging around a little more in Github Desktop and one of the things I tried was to compare branch versions (both to understand the tool a little better but also just to make sure everything was lining up as expected).

To my surprise, it showed no differences…?? (It doesn’t really matter b/c I don’t need the old version anymore but what the what.)

I went to cmd line and ran the same compare command there:

It looks like there are NO changes between the 2 branches. But that’s impossible. I’ve been working from gh-pages1 branch for the past 2 weeks at least. I even checked to make sure by running the git branch -a cmd every once in a while.

While it is completely possible that I messed up something in Git/version control, is there another explanation for this…? I’m clearly even now still on the gh-pages1 branch. How are there no differences?

Not sure, did you do the merge?

Just an FYI. If you use VS Code it comes with Git integration and you can do most things right from the editor, it also has a built-in terminal. So you basically do not have to leave the editor. I’d also check out the GitLens extension for VS Code. You can search for some articles or youtube videos, Google: VS Code Git integration and Google: VS Code GitLens.

If you feel more comfortable using GitHub Desktop then just keep doing that of course. I’m just not sure if you really need it.

Ah good to know. I will look into using VS tools since that is my editor. I only started using Github Desktop recently so not too attached to it. Thanks!

And yes, I did the merge and all is hunky dory. For now :slight_smile:

Good to hear.

BTW, what I meant was if you had done the merge before doing the diff? Maybe a silly question but that would at least explain why there was no difference.

Oh, I see. No, I had not. Too weird for words.

But lesson learned for me: practice Git and any preferred tools on waaay less stressful projects to get comfortable enough on it. :smile: