How to keep an updated git repository with another?

9

I have two repositories in GitHub, the second one being a clone of the first, and for the time being private (for security reasons).

I cloned this second on my machine so I could work on it, but besides my own commits I also need to keep it updated with the first one.

I'm studying about git remote , because if I understood correctly a git remote update would give the message, but I have some doubts, for example:

1 - Is this really the best way to keep one repo updated with another? (the second being private)

2 - If I give a git remote add to link the first repo in this private, and update it, when giving a push I run the risk of sending to the first (public)? Because this can not occur.

    
asked by anonymous 12.11.2015 / 01:54

1 answer

6

If you have a private fork, you probably cloned it like this:

$ git clone [email protected]:<user>/priv.git

The default repository of your copy is therefore [email protected]:<user>/priv.git (called origin ), and is where you send your commits when giving git push .

To add a new remote - let's call it xyz123 (can be anything) - you run the command:

$ git remote add xyz123 [email protected]:<otheruser>/public.git

Note that urls may be different if you are using, for example, https.

From this, the git pull xyz123 command will update your local copy with the latest updates from the xyz123 repository you added. Meanwhile, git push will continue to commit commits to its default branch (in this case, origin ). However if you want you can also send your commits to xyz123 through git push xyz123 .

Note that the pull command has the same behavior: git pull will only update your local copy with updates to the default repository (usually origin ). To update with other repositories you need to specify which one (in this case, git pull xyz123 ).

  • This is the best way to keep your private repo up to date. You always pull of changes in xyz123 and send them to origin by synchronizing them.

  • You will only send commits to your new remote xyz123 if you explicitly specify in your push command. If you do not specify anything, the commit will go to the default repository (usually origin ).

  • 12.11.2015 / 21:32