I am trying to use "git checkout -b" to create a new branch off of a public repository. I was reading something about this at What is the difference between "git branch" and "git checkout -b"?. Tuong Le provided this solution:
git checkout -b [NEW_BRANCH] [FROM_BRANCH]
He added that if there's no FROM_BRANCH, git will use the current branch
.
I am trying to figure out what to use in [FROM_BRANCH]
.
When from my local computer I use git remote -v
, I get this:
origin ssh://[username]@[domain]/~[username]/public_html/public.git (fetch)
origin ssh://[username]@[domain]/~[username]/public_html/public.git (push)
I use SSH to login to the server where I have that public repository and I do this:
# git remote -v
origin /home/[Unix user]/public_html/app (fetch)
origin /home/[Unix user]/public_html/app (push)
# pwd
/home/[Unix user]/public_html/[path to source code]
# git branch
D
newheader
responsivenavigation
bluesidebar
* master
reports
I know that if I simply use git checkout -b mynewbranch
without specifying [FROM_BRANCH]
it is going to create a new branch off of master
because master
is the current branch. That is not what I want. I want to create a new branch off of a branch called mynewbranch
that I have in this public repository: /home/[username]/public_html/public.git
. That is a remote repository that when I use git branch -a
in my local computer, I see it as remotes/origin/mynewbranch
. Thank you.
UPDATE 1: I could easily use this from my local computer: git checkout -b mynewbranch remotes/origin/mynewbranch
. But the thing is that I am not trying to do this from my local computer. I am using SSH to access the server, and from the server, which is where I have this remotes/origin/mynewbranch
, I want to create a new branch off of this remotes/origin/mynewbranch
. When I go to the server and use git branch -a
, I do not see this remotes/origin/mynewbranch
. Where does it reside? How can I create a new branch off of remotes/origin/mynewbranch
from the server where this remotes/origin/mynewbranch
branch resides? The problem is that when I use SSH to log in to the server and use git branch -a
, I do not see this remotes/origin/mynewbranch
branch. I was expecting to see it.
UPDATE 2: The syntax is:
git checkout -b [NEW_BRANCH] [FROM_BRANCH]
I am trying to use this:
git checkout -b mynewbranch origin/mynewbranch
I get this error:
error: pathspec 'mynewbranch' did not match any file(s) known to git.
error: pathspec 'origin/mynewbranch' did not match any file(s) known to git.
UPDATE 3: From my local computer I do this:
git branch -a
One of the lines of the results is:
remotes/origin/mynewbranch
Perfect so far. This means that when from my local computer I used git push origin mynewbranch
, the command did its job to push the code from my local computer to the public repository. That is why I see this public repository on the server: remotes/origin/mynewbranch
. All I want to do now is to checkout on the server the code that I just pushed to this public repository: remotes/origin/mynewbranch
. How do I do that? When I log in to the server where I have the public repository, I use SSH and then I try git branch -a
. I cannot see remotes/origin/mynewbranch
. I want to checkout that branch from the public repository, not from my local computer. How do I do that?