0

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

7
  • Git is entirely built on the concept of history...........the second you have a repository without the history (i.e. just the release commits).........then you basically have a new repository....................what are you trying to accomplish by this workflow? Commented Feb 16, 2021 at 20:47
  • Certainly I can simply copy the code after I have done the release and I will of course also have the release in the second repository but not intermediate steps...The reason is that sometimes it happens that I commit confidential stuff but I still want to provide the code in an easy way....Seems that I simply will copy the release code and commit to the second repo. Commented Feb 16, 2021 at 20:50
  • If you' are trying for that approach, then you can simply squash and rebase all those commits to just the few you are requiring and could push THOSE commits to a new remote..........but my question is why you are wanting to do this? Commented Feb 16, 2021 at 20:51
  • Above this is the actual reason but I was also interested if such a thing is possible with just a second remote on my repository. Commented Feb 16, 2021 at 20:55
  • if you committed sensitive information then this is a very common problem......there are existing solutions to this problem that are worth checking out on google........i recommend not doing the approach you are seeking. hope it helps. Commented Feb 16, 2021 at 20:57

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I'd actually use git commit-tree (plus a few additional operations) to build the second history for remote B, but yes, this should work.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.