简体   繁体   中英

Git pull from another repository

I have a repository called Generic , which is a generic application. I have forked it into a repository called Acme , which just builds upon the application stored Generic repository and adds Acme Co branding to it.

If I make changes to the core functionality in Generic , I want to update the Acme repository with the latest changes I have made to the core functionality in Generic . How would I do that?

As far as I can tell, I am essentially trying to merge the changes made in an upstream repository into the current fork.

If it means anything, I'm trying to do this because I have a generic application that I then build upon and brand for individual clients (like Acme in this example). If there is a cleaner way of doing this, let me know.

Issue the following command in your Acme repo. It adds a new remote repository named upstream that points to the Generic repo.

git remote add upstream https://location/of/generic.git

You can then merge any changes made to Generic into the current branch in Acme with the following command:

git pull upstream

If you just want it to download the changes without automatically merging, use git fetch instead of git pull .

If you want to disable pushing to that repository, set the push URL to an invalid URL using something like

git config remote.upstream.pushurl "NEVER GONNA GIVE YOU UP"

Git will now yell at you about not being able to find a repo if you try to push to upstream (and sorry about the Rickroll, but it was the first random string that popped into my head).

为了从不同的 repo 中提取特定分支,您可以使用以下 git 命令。

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

As @vin mentioned you can pull directly from another repo without adding a new origin (assuming a pull from another repo's master branch to the local master branch):

git pull https://some-other-repo.git master:master 

If the commit histories of the two repos are not linked then --allow-unrelated-histories will be needed but use it with caution, as it implies you know what you are doing.

You can also push a local repo to another repo without adding it as a remote (the remote branch doesn't have to exist so you can use anything you want, eg master:new_branch ):

git push https://some-other-repo.git master:master

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