git - pulling from specific branch

Git

Git Problem Overview


I have cloned a git repository to my dev server and then switched to the dev branch but now I can't do a git pull to update the branch.

How do I update the code on the server ?

Git Solutions


Solution 1 - Git

See the git-pull man page:

> git pull [options] [<repository> [<refspec>...]]

and in the examples section:

> Merge into the current branch the remote branch next: > > $ git pull origin next

So I imagine you want to do something like:

git pull origin dev

To set it up so that it does this by default while you're on the dev branch:

git branch --set-upstream-to=origin/dev dev

Solution 2 - Git

Here is what you need to do. First make sure you are in branch that you don't want to pull. For example if you have master and develop branch, and you are trying to pull develop branch then stay in master branch.

git checkout master

Then,

git pull origin develop

Solution 3 - Git

if you want to pull from a specific branch all you have to do is

git pull 'remote_name' 'branch_name'

NOTE: Make sure you commit your code first.

Solution 4 - Git

It's often clearer to separate the two actions git pull does. The first thing it does is update the local tracking branc that corresponds to the remote branch. This can be done with git fetch. The second is that it then merges in changes, which can of course be done with git merge, though other options such as git rebase are occasionally useful.

Solution 5 - Git

Here are the steps to pull a specific or any branch,

1.clone the master(you need to provide username and password)

       git clone <url>

2. the above command will clone the repository and you will be master branch now

       git checkout <branch which is present in the remote repository(origin)>

3. The above command will checkout to the branch you want to pull and will be set to automatically track that branch

4.If for some reason it does not work like that, after checking out to that branch in your local system, just run the below command

       git pull origin <branch>

Solution 6 - Git

Laravel documentation example:

git pull https://github.com/laravel/docs.git 5.8

based on the command format:

git pull origin <branch>

ļ‘

Solution 7 - Git

This worked perfectly for me, although fetching all branches could be a bit too much:

git init
git remote add origin https://github.com/Vitosh/VBA_personal.git
git fetch --all
git checkout develop

enter image description here


If you want to avoid the overkill of pulling everything and only getting the explicit branch (in this case 'develop'), then the following works:

git init
git remote add origin https://github.com/Vitosh/VBA_personal.git
git fetch origin develop
git checkout develop

Solution 8 - Git

You can take update / pull on git branch you can use below command

git pull origin <branch-name>

The above command will take an update/pull from giving branch name

If you want to take pull from another branch, you need to go to that branch.

git checkout master

Than

git pull origin development

Hope that will work for you

Solution 9 - Git

git-pull - Fetch from and integrate with another repository or a local branch

git pull [options] [<repository> [<refspec>...]]

You can refer official git doc https://git-scm.com/docs/git-pull

Ex :

git pull origin dev

Solution 10 - Git

in my case, Devop was updated(or HEAD) and Main was older(like 20 commits back), using git fetch --all and --allow-unrelated-histories, works perfectly

like this:

git clone https://github.com/xxxxxxxx
git remote add origin https://github.com/xxxxxxxx
git fetch --all

> (here,i got a merge unrelated histories error,so)

git pull origin devop --allow-unrelated-histories

(at this point i got some conflicts that solved with a new commit)

and finally

git push -u origin devop

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlexView Question on Stackoverflow
Solution 1 - GitCascabelView Answer on Stackoverflow
Solution 2 - GitthestarView Answer on Stackoverflow
Solution 3 - GitAli HassanView Answer on Stackoverflow
Solution 4 - GitwnoiseView Answer on Stackoverflow
Solution 5 - Gitvikas etagiView Answer on Stackoverflow
Solution 6 - GitErich GarcíaView Answer on Stackoverflow
Solution 7 - GitVityataView Answer on Stackoverflow
Solution 8 - GitNikunj K.View Answer on Stackoverflow
Solution 9 - GitSeshaView Answer on Stackoverflow
Solution 10 - GitnativelectronicView Answer on Stackoverflow