user1760653
user1760653

Reputation: 181

GIT push tag second remote

Is it possible to have a local repository with two remotes while remoteA is used to develop while on remoteB I only want to have the relese tags but without the history. Say, for the third tags I have a lot of commits on remoteA but only three commits on remoteB (tags + master).

Thanks

Upvotes: 0

Views: 262

Answers (1)

joanis
joanis

Reputation: 12201

You can use git reset with a path to effectively copy the files from a commit on remoteB to your current state. If you're currently sitting on the commit at the HEAD of remoteA, that might do what you want.

Let's assume you have the latest release state in remoteB/releaseN.

Let's also assume you have a branch called published on remoteA, where you want to push one commit jumping right to remoteB/releaseN without the history.

The recipe

git checkout published       # must have remoteA/published as upstream
git merge remoteA/published  # just in case, to make sure it's in sync
cd <root directory of your sandbox>
git reset remoteB/releaseN -- .
git commit -m"jumping to releaseN"
git push remoteA published
git reset --hard

Explanations

  • In the first two commands, I'm just making sure you're on branch published, with should have remoteA/published as its upstream, and be up to date to with.

  • The git reset remoteB/releaseN -- . command, run from the root directory of your sandbox, "copies" all files in . from their state in remoteB/releaseN to the cache, though it does not change your working files. So a commit here will create the commit you want, with no history, which you can then push.

  • Since the reset operation didn't change the files in the sandbox, only the cache, I added a hard reset at the end, to sync your sandbox with the commit you just made.

Limitations

This technique only creates the "copy" commits. If you wanted tags too, manually recreate and push them in a different sandbox with only remoteA as remote if you want the same names. If you try to push them from your sandbox with the two remotes with the same names, you'd have a collision since those tags are pointing to unrelated commits between the two remotes.

Upvotes: 2

Related Questions