msln
msln

Reputation: 1533

How to get a specific branch by url? Git

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:[email protected]/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?

Upvotes: 5

Views: 11488

Answers (1)

IMSoP
IMSoP

Reputation: 97898

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:[email protected]/myrepo.git, and can add a branch name as the <refspec> to give quite simply:

git pull myuser:[email protected]/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:[email protected]/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.

Upvotes: 3

Related Questions