# What's the best way to push/fetch replace refs?

3 messages from 2011-12-30 to 2012-01-02. Participants: Slawomir Testowy, Christian Couder.
Thread: https://gitlist.dev/t/29270

## Slawomir Testowy, 2011-12-30 11:59

Subject: What's the best way to push/fetch replace refs?
Message-ID: <CAA61mJgCjt0O5LE5OQ=aNbtUHCZeZdZ=3dXYTNv_AhFi7JXwkA@mail.gmail.com>
URL: https://gitlist.dev/e/CAA61mJgCjt0O5LE5OQ%3DaNbtUHCZeZdZ%3D3dXYTNv_AhFi7JXwkA%40mail.gmail.com

```
I want to use git-replace to connect two disjoined commits (git-svn didn't
detect massive file movement) and I want to share these replace refs with others
(we're moving from svn to git). I cannot use git-rebase because the history
after the split contains lots of branches and merges and using git-rebase for
that is an overkill.

I did something like this:

# Setup some repositories and create basic commit.
git init --bare repo
git init a
git init b
cd a
echo a > a && git add a && git commit -m initial
git branch tmp
echo b > b && git add b && git commit -m second
git checkout tmp
echo c > c && git add c && git commit -m replacement

# Replace a commit with another one
git replace `git rev-parse master` `git rev-parse tmp`

# Push changes to public repo; this doesn't push replace refs.
git push --all ../repo/

# Is this the best way to push replace refs?
git push  ../repo/ 'refs/replace/*'

# Fetch commits from public repo
cd ../b/
git pull ../repo/

# We didn't fetch replace refs in previous git-pull. But this seems to
work. Is this the correct way?
git fetch ../repo/ 'refs/replace/*:refs/replace/*'

# I also added "fetch = +refs/replace/*:refs/replace/*" to [remote
"origin"] in "b" and this also seems to work.

```

## Christian Couder, 2011-12-30 14:51

Subject: Re: What's the best way to push/fetch replace refs?
Message-ID: <CAP8UFD3KSjdZz1q+QYsH4JpRkiavtTbT1WqQSdxqCaxc24j=Rg@mail.gmail.com>
URL: https://gitlist.dev/e/CAP8UFD3KSjdZz1q%2BQYsH4JpRkiavtTbT1WqQSdxqCaxc24j%3DRg%40mail.gmail.com
In-Reply-To: <CAA61mJgCjt0O5LE5OQ=aNbtUHCZeZdZ=3dXYTNv_AhFi7JXwkA@mail.gmail.com>

```
On Fri, Dec 30, 2011 at 12:59 PM, Slawomir Testowy
<slawomir.testowy@gmail.com> wrote:
>
> # I also added "fetch = +refs/replace/*:refs/replace/*" to [remote
> "origin"] in "b" and this also seems to work.
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

Yeah, the simplest is probably to just add "fetch =
+refs/replace/*:refs/replace/*" to the remote(s) you want to get the
replace refs from, and "push = +refs/replace/*:refs/replace/*" to the
remote(s) you want to push the replace refs to.

Regards,
Christian.

```

## Slawomir Testowy, 2012-01-02 06:16

Subject: Re: What's the best way to push/fetch replace refs?
Message-ID: <CAA61mJjCKJYAifD3DihAg+pH4Q0Z9y26n3P5KBBy09n-wK9LXg@mail.gmail.com>
URL: https://gitlist.dev/e/CAA61mJjCKJYAifD3DihAg%2BpH4Q0Z9y26n3P5KBBy09n-wK9LXg%40mail.gmail.com
In-Reply-To: <CAP8UFD3KSjdZz1q+QYsH4JpRkiavtTbT1WqQSdxqCaxc24j=Rg@mail.gmail.com>

```
2011/12/30 Christian Couder <christian.couder@gmail.com>:
> On Fri, Dec 30, 2011 at 12:59 PM, Slawomir Testowy
> <slawomir.testowy@gmail.com> wrote:
>>
>> # I also added "fetch = +refs/replace/*:refs/replace/*" to [remote
>> "origin"] in "b" and this also seems to work.
>
> Yeah, the simplest is probably to just add "fetch =
> +refs/replace/*:refs/replace/*" to the remote(s) you want to get the
> replace refs from, and "push = +refs/replace/*:refs/replace/*" to the
> remote(s) you want to push the replace refs to.
>
> Regards,
> Christian.

Thanks Christian, I thought maybe there is some magic "git clone
--get-also-replace-refs" or something. I'm asking because I'm about to
tell people how to clone my repository and some of them don't know Git
at all so I wanted to find out the simplest/best way to fetch replace refs.

Thanks.

```
