How do I keep one git repository updated with another?

Asked

Viewed 838 times

10

I participate in two repositories on Github, the second being a clone of the first, and for now private (for security reasons).

I cloned this second on my machine to be able to work on top, but in addition to my own commits I also need to keep it updated with the first.

I’m studying about the git remote, because I understood a git remote update I could handle it, but I still have some doubts, for example:

1 - Is this really the best alternative to keep one Item up to date with another? (it being necessary that the second one be private)

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

Diagrama

1 answer

6


If you have a private register, 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 (call for origin), and that’s where you send your commits when you give a git push.

To add a new remote - let’s call it xyz123 (can be anything) - you execute 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 command git pull xyz123 update your local copy with the latest repository updates xyz123 you added. Meanwhile, git push will continue sending commits to your default branch (in this case, origin). But if you want you can also send your commits to xyz123 through git push xyz123.

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

  1. This is the best alternative to keep your private Object up to date. You always do pull of changes in xyz123 and sends them to origin, synchronizing them.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.