0

I am working on Branch A while other dev working on Branch B.

I wanted to pull everything in Branch B to Branch A. I have cloned both branches in my local.

What I did upon reading one of the SO post:

git checkout branch B
git pull 
git checkout branch A
git merge branch B

And the merge message were following:

Auto-merging fileBar
Merge made by the 'recursive' strategy.
 .../file               | 92 ++++++++++++++++++----
 file1     |  9 ++-
 .../file2          |  2 +-
 .../file3                       |  6 +-
 .../file4                     |  4 +-
 .../file5              |  2 +-
 file6   |  2 +-
 .../file7               |  4 +-
 8 files changed, 91 insertions(+), 30 deletions(-)

However, i was expect to solve some merge conflict, i was surprised that git does not yell at me for this.

So what I did after this point:

git status

It shows that nothing in my local is changed, weird?

then i did:

git log

which shows:

Author: me <me@gmail.com>
Date:   Mon Mar 18 14:47:00 2019 -0400

Merge branch 'B' into A

I also tried to pull branch B while on branch A:

git pull origin branchB

but it says it is update to date:

From https://github.com/myGit/myRepo
 * branch              BranchB -> FETCH_HEAD
Already up to date.

However, when I log on to Git, those repos are clearly not the same on remote.

At this point, I am confused. what happened here? How do I pull branch B into branch A?

Update: I just found out that when i did:

git checkout branch B
git pull

The new changes were not actually pulled. when I did git pull, it says it is already up to date, while it is clearly not. My local still have the old version of branch B. How? I am confused by everything at this point

What I have tried:

git fetch --all
git reset --hard origin/BranchB

None of these worked

ZpfSysn
  • 807
  • 2
  • 12
  • 30
  • are you positive the other Dev "pushed" his changes to branch B on the server? – Jeff R. Mar 18 '19 at 20:52
  • 1
    @JeffR.Yeah, because when I lok at git, i do see he commited the changes. One thing worth mentioning is that, I pulled my branch through --single-branch command, if that's relevant – ZpfSysn Mar 18 '19 at 21:01
  • 1
    I'm guessing you mean you *cloned* with `--single-branch` (pull has no such option). That is somewhat relevant—a single-branch clone is deliberately limited (some might say "crippled" but that's probably too strong). If you undo the single-branch-ness the repository will be much better behaved. – torek Mar 18 '19 at 21:49

1 Answers1

0

It seems like everything worked properly.

git checkout branch B
git pull 
git checkout branch A
git merge branch B

After you ran the above, A was merged with B (which you confirmed with git log and git pull origin branchB).

git status correctly showed no staged/unstaged changes in the working tree, all of the changes get committed with the merge.

The fact that there were no conflicts is a bit more complicated. You may want to review methods for dealing with branches that depend on each other. The simplest way to use branches, is to work on isolated "feature branches" that don't depend on one another. You merge the branches into master when they're ready, and then you pull master into the other branches to keep them up to date.

The remote branches (on GitHub) won't be updated until you git push, which it doesn't seem like you've done.

Additionally, it seems like you've now reset A to be the same as B (git reset --hard origin/BranchB) and potentially lost any work you've done on A. To remedy this, use git reflog to see a history of your recent actions, and then do git reset --hard $REFLOG_HASH where the HASH is the numbers to the left of the action where you did the merge - so that you can reset your working tree to that point in history. And then you can use git push to update the remote.

JBallin
  • 8,481
  • 4
  • 46
  • 51