tags:

views:

43

answers:

1

Here is what I did:

Cloned a remote repository to my local computer. Created a second clone from the first clone. Made changes in the second clone. Never touched anything that resides in the first clone.

Now what happens if I directly push to remote repo from the second clone? A new branch is introduced in the remote repo?

Maybe a stupid question but I can't test it because there are other developers working on the code and I don't want to mess anything.

Thanks.

A: 

Hi yang,

Now what happens if I directly push to remote repo from the second clone? A new branch is introduced in the remote repo?
What you would want to do in this situation is clone the central repo again (in case any other programmers made changes) merge your changes with those, and then push that back to the central repo.

This ensures that your branch is now part of the main branch again.

Metropolis

EDIT
Maybe this will be a little more clear

  1. Clone repo1 to your machine
  2. Make a clone of repo1 on your machine to keep the original in tact
  3. Make changes to repo2 on your machine
  4. Pull changes from repo2 to repo1, merge (if needed)
  5. Clone CR again (in case other programmers made changes)
  6. Pull changes from repo1 to the newly cloned repo (merge if needed)
  7. Push newly cloned repo back to CR
  8. Clone CR again and remove all of your repos to get the newest copy
Metropolis
Thanks for the answer Metropolis. Based on your answer, if I want others to see what I do in my branch, I simply need to push from my local branch to the central repo. So my local clone appears as a remote branch to others, right?
yang
You dont want to "push" first. If you push first without merging your changes with the CR, then there will be a hanging branch in the CR. This is why you should first clone the CR again, merge your changes with that, and then push it back. Just remember that if you are ever worried about messing things up, you can always clone the CR to your system and play around with the repository however you want.
Metropolis
Sometimes the extra clone step is unnecessary, but when you have multiple programmers working off the same repository, its better to clone it and check if they made any changes first. If your repository (before your changes) is on the same changeset as the CR, then you can just push without merging. But always check this first.
Metropolis
Thanks for this clear description. On step 5 do I have to clone again? Isn't updating sufficient?
yang
On step 5 you would either want to clone, or you could pull from the CR....You do not want to push directly to the CR if you have made changes. But cloning in that step is better in my opinion because then you have the newest copy of the CR to work with however you want. If you pull from the CR, then your repo will automatically be getting updated, which may cause you to have to revert if you find you did not want the changes. Cloning is cheap, doing it as often as possible helps to avoid problems.
Metropolis