1

I have three branches (in DevOps), A, B, and C. In my case, A is the main, B is a development trunkline, and C is a feature being developed for B.

While working on C, I'd like to be pulling changes from B when I fetch and pull. However, when I push, I only want to push to C. I want to be forced to create pull requests to merge C back into B.

After doing some reading, I learned that I could set B as the upstream of C like I would be used to seeing with a forked repository on GitHub. I utilized the following command to do so:

git branch --set-upstream-to origin/B

However, this doesn't just pull from B, it also pushes changes to B when I use Visual Studio Code's sync changes button:

Screenshot of the sync changes button for reference.

How do I ensure that a push, only pushes changes to the repository for C, while pulls will pull changes from B?

Hazel へいぜる
  • 2,751
  • 1
  • 12
  • 44
  • I made a small change to verify where the push and pull were going, and it is indeed not separated, nor does it push to ***C*** at all. It pushes and pulls directly to/from ***B***. – Hazel へいぜる Jan 13 '22 at 03:55
  • Does this answer your question? [Easier way to keep a git feature branch up to date](https://stackoverflow.com/questions/9587686/easier-way-to-keep-a-git-feature-branch-up-to-date) – Matt Jan 13 '22 at 04:29
  • @Matt I'm hoping that's not the answer here; perhaps there's something VSCode itself can offer to maybe set the target of pull and push separately? I'm still actively researching this, so if I find something outside of aliasing or scripting, I'll be sure to come back and update. – Hazel へいぜる Jan 13 '22 at 04:39
  • 1
    Maybe this then, [How to set up branches with different pull/push upstreams](https://stackoverflow.com/questions/45638858/how-to-set-up-branches-with-different-pull-push-upstreams). Although personally, I like to issue explicit commands so it is obvious what you are getting. I feel like merge/rebase steps are a pretty fundamental part of git. – Matt Jan 13 '22 at 04:56
  • 1
    This is a VSCode "feature" so presumably tag [tag:git] doesn't apply. You *used* [tag:git], though, so: In command-line Git, `git config push.default` can be used to control how `git push` behaves when the upstream of `C` is set to `origin/B`. – torek Jan 13 '22 at 05:08
  • @torek I'm not necessarily focused on the button itself, I just included it to give a better picture of what I'm doing on my side. VS Community behaves the same, so I assumed I might need some additional git commands to get it set up properly. – Hazel へいぜる Jan 13 '22 at 13:58
  • I don't think VSCode or VSCommunity obeys the `push.default` settings, but I don't actually *use* either of those. You can create a test repo and do some experiments. See [the `git config` documentation](https://git-scm.com/docs/git-config) under `push.default` for what the settings are. – torek Jan 13 '22 at 21:26

0 Answers0