1

I've been working on a webpage and I've come across an issue with having my local Git and Github synced. This is what I've been doing:

  1. I started off with the master branch
  2. I created a branch called "header" for the page's header.
  3. I committed the changes and pushed them up to Github
  4. I did a PR and merged "header" with master
  5. I repeated this step for the "main" branch
  6. I repeated this step for the "footer" branch

Now, I've been switching randomly from "header", "main", and "footer" as I keep building my webpage.

I now have the problem with my Gibhub showing me these messages:

For the "header": This branch is 8 commits behind master

For the "main": This branch is 3 commits behind master

For the "footer": This branch is 1 commit ahead of master

I tried to PR as much as possible so that my "master" branch has EVERYTHING that I want in it, and that's currently what I have. How do I have them synced up with the master? Did I screw this up big time?

Thank you.

geenpill
  • 119
  • 8

2 Answers2

2

Considering your branches are merged to master 'through Pull Request) at different point in time, it seems expected you would get various "n commit behind master" for each branch

If you want to reset one of those branch to your current master (which currently has everything), simply recreate it locally, and start working on it starting from the latest master:

git switch master
git pull
git branch -C header
# work on header
git push --force # for the first push only, or
git push --force-with-lease # for the first push only, 
                            # if you are not alone working on the repository
# make a new PR

(see "git push --force-with-lease vs. --force")

The idea is to not rebase header on top of master, since it has been merge to master before.
But simple to recreate header on top of master, in order to make a new header PR.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

Actually, this is something that I face daily! It would be good if you can start off each of these steps without having any local changes in your machine.

git fetch --all
git checkout master
git merge # at the end of this step, your local copy of `master` and the remote copy should be in sync. You can verify this by running `git log -1` - and all the copies of master should show up in the metadata
git checkout header
git merge # at the end of this step, your local copy of `master` and the remote copy should be in sync. IF you don't have any differences (ie incoming changes), you can skip this step.
git rebase master # This might rebase correctly or cause conflicts - if do, you will have to resolve them
git push --force-with-lease origin header

You will want to repeat the above steps for each of the branches that you have header, main, footer. HTH