Reputation: 100200
I have these lines in a bash script:
git checkout -b foo "origin/dev"
git push -u origin HEAD
what I want to do is create a new branch foo whose parent is origin/dev. (Correct my terminology please).
The problem is I get:
Branch foo set up to track remote branch dev from origin.
What does that mean exactly? When I checkout foo and do git push, I want it to be pushed to a branch called foo on the remote. I thought when a local branch tracked a remote that when you pushed the branch it would to go to the tracking branch right?
Upvotes: 0
Views: 1607
Reputation: 489223
Branches do not have parent branches.
Branches do have upstream settings. More specifically, each branch name (each local name of the form refs/heads/name
) can have one (1) upstream, or not have an upstream.
When creating a branch with git branch
or git checkout -b
, if you choose to set the new branch's upstream at that time, Git prints out the message you quoted:
Branch foo set up to track remote branch dev from origin.
This means that your refs/heads/foo
has, as its one allowed upstream, the name origin/dev
.
When using git checkout -b
to create a branch, if you don't want the new branch to have an upstream, either:
Don't name a valid upstream. For instance:
git checkout -b foo
creates new branch foo
pointing to the current commit, without setting an upstream for new branch foo
.
Use the --no-track
option to tell Git not to set the upstream, even though you are using a name that is suitable to install as the upstream:
git checkout --no-track -b foo origin/dev
However, there's no problem with having foo
's upstream set to origin/dev
because you can change or remove this setting at any time using git branch
:
git branch --unset-upstream foo
will remove the current upstream from foo
, while:
git branch --set-upstream-to=origin/xyzzy foo
will set foo
's upstream to origin/xyzzy
. The one constraint with this last command is that origin/xyzzy
must actually exist.
(Note that very old versions of Git do not have --set-upstream-to
. Instead, they have --set-upstream
, which does the same thing, but requires that the order of arguments be swapped. This turned out to be a common source of mistakes, so modern Git deprecates the old --set-upstream
option, replacing it with --set-upstream-to
which is easier to use correctly.)
Upvotes: 2
Reputation: 24184
Branch foo set up to track remote branch dev from origin.
it's mean your local foo
branch is tracking remote dev
branch. So, git push
will push to dev
branch. You need to change the tracking branch to remote foo
branch.
One of the way is following:
Push to remote foo
branch from local foo
branch:
$ git push origin HEAD:foo
Set the upstream of local foo
branch to remote foo
branch:
$ git branch foo --set-upstream-to origin/foo
Or,
$ git branch foo -u origin/foo
Now, local foo
branch is tracking to 'remote foo' branch. So, just git push
will push to remote foo branch.
Upvotes: 1