0

Let's say I have branch "A", from which a more advanced branch "B" was created.

Usually all the changes that are implemented on branch "A" should be just pulled into branch "B", but due to some differences between the branches a specific feature was implemented on "A" and "B" separately and in different ways.

What I want to do is to stand on branch "B" and do "git pull origin A", but without actually pulling any file changes, so that git will just think that B and A are synced at this specific point, and any additional "git pull origin A" command will just return that there's nothing pull and no changes detected (until the next commit to branch A).

Is it possible to do so?

user1483597
  • 540
  • 2
  • 4
  • 20
  • i dont really understand what you wanna do. What's the point of pulling if you're not syncing the 2 branches? – skytorner Oct 20 '22 at 10:15
  • so that anything new that will be added to branch A can be pulled to B without pulling the previous feature implementation that i don't need on B (that has a different implementation of it) – user1483597 Oct 20 '22 at 10:20
  • Does this answer your question? [How to keep the local file or the remote file during merge using Git and the command line?](https://stackoverflow.com/questions/6650215/how-to-keep-the-local-file-or-the-remote-file-during-merge-using-git-and-the-com) – IMSoP Oct 20 '22 at 10:20
  • Other possibly relevant questions: https://stackoverflow.com/questions/4911794/git-command-for-making-one-branch-like-another https://stackoverflow.com/questions/53824861/how-to-make-git-merge-use-theirs-not-only-for-the-conflicts-but-also-for-the-unc Useful search terms if none of those is quite right: "merge" (more general than talking about "pull" specifically) and "ours" and "theirs" (how git generally refers to the two sides of a merge). – IMSoP Oct 20 '22 at 10:25
  • 1
    "git pull -Xours" works only on conflicts, I also need to ignore other file changes that are not causing conflicts (i can obviously revert them all all manually, just wanted to know if there's a single command for it) – user1483597 Oct 20 '22 at 10:28

3 Answers3

1

It can be done with a little bit of tweeking. First run the merge and let it finish, as you normally do (any workflow.... pull, merge).

git checkout B
git merge -m "Merging A" A

After doing that, let's get back the content that we had in B before the merge

git restore --staged --worktree --source=@~ -- .
git commit --amend --no-edit
eftshift0
  • 26,375
  • 3
  • 36
  • 60
0

The usual pattern I follow here is to first do:

# on branch B
git fetch origin

This will update all your tracking branches, including origin/A, which is the tracking branch for A. Now you may do whatever operation you wanted from the B branch. For example, you could merge A into B:

# still from B
git merge origin/A

Note that you were able to achieve all of this without ever changing branches.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

You are looking for the merge strategy ours:

git checkout B
git merge -s ours A
# or
git pull -s ours origin A

The merge strategy creates a merge, but does not change the working tree in any way. This essentially ignores the changes made on the merged branch A.

j6t
  • 9,150
  • 1
  • 15
  • 35