简体   繁体   中英

Locally add the remote to the GitHub original (forked from) repository

Let's say I have a GitHub fork ( https://github.com/sitaktif/foo ) of an existing repository ( https://github.com/someguy/foo ).

I have a local git repository which has only one git remote ( origin ), pointing to my GitHub fork:

# Output from `git remote -v`
origin  git@github.com:sitaktif/foo (fetch)
origin  git@github.com:sitaktif/foo (push)

I would like to add the parent repository to my remotes (ie the repository I forked from initially on GitHub), so that it eventually looks like this:

# Output from `git remote -v`
origin  git@github.com:sitaktif/foo (fetch)
origin  git@github.com:sitaktif/foo (push)
upstream    https://github.com/someguy/foo (fetch)
upstream    https://github.com/someguy/foo (push)

I know I can add the remote manually but what I want is to do this automatically (so that I don't have to manually find the address of the parent/original repo for each of my local repositories).

The only solution I have found so far is to use the GitHub API in a script.

I have created one and made it available there: https://github.com/sitaktif/github-utils/blob/master/github_add_upstream.py

I included minimal documentation in case anybody is interested. Feel free to suggest improvements to the scripts. The code is far from being perfect, so pull requests are welcome.

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