In my server, I've written a bash script that gets last changes from my Github repo.
I pull the latest master
branch with url as following:
git pull myuser:mypassword@github.com/myrepo.git
Now I want to get a specific branch in this bash script? Not clone
, I want to pull
a specific branch. Is it possible to do that with URL?
Asked
Active
Viewed 7,175 times
4
-
Does this answer your question? [How do I clone a specific Git branch?](https://stackoverflow.com/questions/1911109/how-do-i-clone-a-specific-git-branch) – Brian61354270 Mar 14 '20 at 14:43
1 Answers
2
The manual page for git pull
summarises the command format as:
git pull [<options>] [<repository> [<refspec>…]]
<options>
are all the optional arguments beginning with-
<repository>
is specified either as a URL or a pre-configured "remote"<refspec>
is most commonly the name of a branch
So in your example, you have a repository argument of myuser:mypassword@github.com/myrepo.git
, and can add a branch name as the <refspec>
to give quite simply:
git pull myuser:mypassword@github.com/myrepo.git some-branch-name
More commonly, you would set up a "remote", which is just an alias for that repository URL:
# set up once
git remote add some-memorable-name myuser:mypassword@github.com/myrepo.git
# use from then on
git pull some-memorable-name some-branch-name
That's why you'll see plenty of examples online of commands like git pull upstream master
- upstream
refers to some particular remote repository, and master
is the branch to fetch and merge.

IMSoP
- 89,526
- 13
- 117
- 169