Henry Dikeman
Henry Dikeman

Reputation: 89

Is there a way to connect a git repo to 2 remotes at once?

I have an ongoing project at my university working as part of a professor's research group. Up until now, I have been using a private repository on my personal Github account to store my work (on github.com/user/repo). However, my university also has a separate enterprise Github server, and my professor wants me to also store my work on the university's server (github.university.com/user/repo) since that will make handing off the project easier once I leave the group, among other reasons. The issue is that I already have a lot of work done in my personal repo, and I'd like to be able to see it after I'm no longer a student (which will be soon).

My professor doesn't care if I keep my work in my personal repository, as long as it is also tracked in the university Github.

I want to know: is there a way to link my existing, private repository to a repository in my university's enterprise Github server? I'd like to:

  1. Be able to commit changes to both repos simultaneously (i.e., link to the university GitHub repo and my personal Github repo both at once, and commit changes simultaneously to both with one set of commands, like git push to push changes to github.university.com/user/repo and github.com/user/repo at once)
  2. If that's not possible, I'd like to at least retain the commit history of my personal repo when I copy into my university's server, which might be simple but I'm a bit afraid of screwing up my existing work

Beyond simple branching and merging, I'm not great with git, and this sort of niche use-case feels above my pay grade. Thank you in advance!

Upvotes: 0

Views: 52

Answers (1)

matt
matt

Reputation: 534950

is there a way to link my existing, private repository to a repository in my university's enterprise Github server

Absolutely. Just add it as a remote:

git remote add uni <universityURL>

Now when you say

git push origin mybranch

you are pushing the branch to your repo, but when you say

git push uni mybranch

you are pushing it to the university repo.

(I use this technique all the time, as a backup to my backup. What if GitHub goes down? It does happen. So I also have a Bitbucket account, and I push to both, figuring they won't both be down at once.)

Upvotes: 3

Related Questions