Git pull from a specific branch to a specific branch

We use the github repository as our "central repository".

We plan to use several encoders on an intermediate server as follows:

  • Encoders work on a separate branch on their local repo;
  • Encoders push changes to github; and then
  • Encoders fetch updates from github to server repo

So, in practice, in step 3, the encoders will run the following on an intermediate repo:

git checkout coderA-updates
git pull origin coderA-updates
git checkout master

Is there a way to update a specific branch without specifying git checkout first?


TL; DR: How do you do something like git pull origin remoteBranch localBranch without having to switch active branches?

Thanks:)

+4
source share
3 answers
 git checkout branchB git pull origin branchA 

This receives the changes that occurred in branchA , and merges them into a local branchB .

git help merge says:

Includes changes from named commits (from the moment of their history, deviated from the current branch) to the current branch.

So, I believe that it is impossible to work with two branches without making one of them current.

You can use git stash in your active branch to save the changes, then check branchB and pull branchA . After the merge is complete, you check the branch in which you hid the changes and use git stash apply .

Or you can simply commit the changes before checking / pulling.

Hope this helps.

+1
source

Use simple fetch :

 git fetch origin remoteBranch:localBranch 

This will only work for quick changes by default (see docs ).

+1
source

From git help pull :

SYNTAX

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

DESCRIPTION

[...]

may call an arbitrary remote ref (for example, a tag name) or even a collection of links with appropriate remote branch tracking (for example, refs / heads /: refs / remotes / origin /), but usually it is a branch name in a remote repository.

So you can do git pull remoteBranch:localBranch and it will work.

0
source

Source: https://habr.com/ru/post/1446932/


All Articles