Reputation: 329
I have a master branch that's been pulled from staging. There's a production branch that's ahead of master that I want to base my feature branch off of.
git ls-remote
doesn't show a reference to the branch I need to pull from. Do I need to set a new master or rebase to do this? I'm looking for a way to keep the master as it is (staging) and be able to pull from branches ahead (prod).
Edit:
I've attempted to checkout the production branch itself but it's throwing an error:
-> git checkout release-0000
error: pathspec 'release-0000' did not match any file(s) known to git.
More Edit:
So while git ls-remote
didn't show the remote branch I was trying to pull from--release-0000
, git branch -a
and git branch -r
contained the name of the branch it the list. My attempt to pull/checkout the branch by its name, release-000
didn't work, I'm assuming because it was lacking its "full path" which is origin/release-000.
When referred to the branch name including origin,
git recognized the production branch and I was able to checkout.
Upvotes: 1
Views: 1510
Reputation: 83537
If you do not already have a local version of the feature branch, you need to create it with
$ git checkout origin/feature
$ git branch feature
or as a shortcut
$ git checkout -b feature origin/feature
Now you can create a new branch with and check it out with
$ git branch <new-branch-name>
$ git checkout <new-branch-name>
or
$ git checkout -b <new-branch-name> feature
Note that feature
on the end of the above command is optional if you already did git checkout feature
. However, the version I used above is useful when you are not currently on the branch which you want to use as the base for a new branch.
Here's a head scratcher:
According to the documentation for git checkout
:
If is not found but there does exist a tracking branch in exactly one remote (call it ) with a matching name, treat as equivalent to
$ git checkout -b <branch> --track <remote>/<branch>
So the fact that git checkout <branch>
failed for you tells me that you most likely have two remotes with the same branch name.
Upvotes: 0
Reputation: 1890
Just checkout the production branch and create a new branch from there. So that all commits in production branch which is ahead of master is pulled to that new branch
Upvotes: 1