简体   繁体   中英

Git pull a branch from a different repository

I've few files in my current repository. I want to merge a remote branch from a different repository.

  1. Pull and merge a branch from github.com/username/code.git (branch loader)
  2. Then pull and merge a branch from github.com/username/code.git (branch login)

Is it possible or what's the workaround? I wanna keep adding code to my current branch from different remote branches.

You can add other origins for your repository using

git remote add new_origin git@theUrlToRepo

You can now start pushing/pulling and basically doing all operations on both of your remotes.

git push origin master
git push new_origin master

git pull origin master
git pull new_origin master

You just have to specify which remote you're doing your operations with and you're set.

In your specific usecase, after adding remote repos and naming them, you'd do something like the following to merge remote branches into your local workspace.

git merge origin/loader
git merge new_origin/login

do this from your original repo that you want to merge the new code into:

for me i just created a new branch with the same name first:

git checkout -b my_new_branch

then i added the other origin:

git remote add new_origin http://someRepo.git

then i simply pulled the branch from new_origin into my current repo:

git pull new_origin my_new_branch 

the git pull command should do a fetch and merge for you.

You can just

git pull url branch

it works

你也可以这样做

git pull <git_pull_url> <branch> --allow-unrelated-histories

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM