11/18/2023 0 Comments Git set upstream to different branchThe newly created branch will point to this existing commit. Git needs the hash ID of some existing commit.Git needs the name of the new branch it should create.When we choose to create a new branch-with git branch, git checkout -b, or git switch -c-we must give Git two things: The git push will this time call up origin and attempt to have the Git repository at origin update that other Git repository's branch br1 (the branch on the other Git that we remember, locally, as origin/br1). However, if we then run: git branch -set-upstream-to=origin/br1 We will get an error from git push because the name br2 in origin/br2 does not match the name br1. If we run: git branch -set-upstream-to=origin/br2 If this is set to simple-as it normally is today-this kind of git push will only push to the upstream of the current branch, and only if the upstream is set to a remote-tracking name that-once the remote part is removed-matches the current branch.įor example, suppose the current branch is named br1, and both origin/br1 and origin/br2 exist. In command line Git, the behavior git push, with no additional arguments, is controlled by the fault setting. a remote-tracking name like origin/somebranch.If it had no upstream before, this operation does nothing otherwise, it removes the upstream setting. To unset the upstream, use git branch -unset-upstream: git branch -unset-upstream If it previously had origin/otherbranch set as its upstream, that upstream is now removed, because only one upstream can be set: origin/somebranch is now the upstream. The current branch now has origin/somebranch set as its upstream (unless the command failed, in which case nothing has changed). To set a particular upstream, use git branch -set-upstream-to: git branch -set-upstream-to=origin/somebranchįor instance. A branch either has an upstream set, or does not have an upstream set. That said, each branch, in Git, can have one upstream set. ![]() It's like assuming that a 1980s-era automobile has self-driving capability. It's important to know and understand this if you think that branches mean something in Git, you will eventually hurt yourself. Important backgroundīranches are not created from branches. ![]() Visual Studio apparently (mis)uses this to decide to ask the remote to update its test branch. But you still have to remember to do it (once you'll get reminded when you run git push without -u origin mybranch).It's because the upstream of your new branch is set to origin/test. It's just more convenient since you can do it together with the push that creates the branch at origin. Note that this is the same as running git branch -set-upstream-to: you do it once, after which it's set locally and you don't have to do it again. Which tells your local git to push mybranch to origin and, once that's done, set up origin/mybranch as the tracking-branch for mybranch. In this particular case, on the first push (the one that will create the branch upstream), you can use: git push -u origin mybranch On the other hand, if origin/mybranch does not exist yet and you're creating mybranch locally with git checkout -b or similar, you can't really set it to track the upstream branch that does not exist yet (you can configure it to track that branch but you'll get an occasional complaint that the upstream version is not there). If you are creating mybranch locally with git checkout and it already exists as origin/mybranch in your local repository, you can simply git checkout mybranch and your local git will see that origin/mybranch exists and create local mybranch with origin/mybranch as its upstream. It's not github, it's your local git, that does all this. Workflows most likely to benefit from this option are simple central workflows where all branches are expected to have the same name on the remote. It is useful if by default you want new branches to be pushed to the default remote (like the behavior of fault=current) and you also want the upstream tracking to be set. If set to "true" assume -set-upstream on default push when no upstream tracking exists for the current branch this option takes effect with fault options simple, upstream, and current. Note: The -global flag means this will apply to all git commands on your machine (regardless of which repo it is), you can omit the flag to make it specific to a single repo on your machine. Then git push will automatically setup the remote branch. Run to update your configuration: git config -global -add -bool toSetupRemote true As of git 2.37.0, this is now possible with git configuration.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |