Google copybara: moving code between repositories

github.com

285 points by reconnecting 19 hours ago


dijit - 8 hours ago

Ha! This post comes right at the time where I finally got around to open sourcing the patches I made to provide Perforce support which I use at my gamedev studio[0].

I find it kind of funny that perforce support was not included, only git support seems to exist in any meaningful way: despite the primary use of copybara being for releasing internal google code (which lives in Piper, a fork of Perforce).

I actually got a bit worried when looking at the git history before making the PR, because there's a lot of Gerrit Change-ID markers (meaning there's some gerrit code review system somewhere which I'm not privvy too) and I might have submitted a PR which never gets upstreamed..

I feel the same pang of pain from the lack of a perforce version of Gerrit/Rietveld.. but, you can't ask for everything!

[0]: https://github.com/google/copybara/pull/347

MarkSweep - 17 hours ago

Some other interesting tools in the space. Rust is using a tool called Josh to sync commits:

https://josh-project.dev

The blog post from the Rust people:

https://blog.rust-lang.org/inside-rust/2026/06/04/how-josh-h...

Meta used to have an open source tool called fbshipit. But according to its open source repo they no longer use it:

https://github.com/facebookarchive/fbshipit

Any others in this space?

schrodinger - 17 hours ago

To those who have used it: is it handy for situations where you have multiple repos that want to share a little code, but it's not worth the trouble of extracting a library, referencing it, publishing versioned releases, updating dependent repos, etc?

And instead just "sync" a code folder from one main repo (perhaps containing common domain models) to other repos?

Basically the Go philosophy that a little bit of copying is better than a lot of dependency?

klodolph - 14 hours ago

Been using this for a while, mostly when I make a tool as part of a larger project and the tool is big enough to deserve its own release.

It’s powerful enough to do a whole bidirectional shipping operation where you export and import code—no thanks, that’s a hassle. I use it mostly for a simple fire and forget export, where I take a folder out of its original repo and preserve the history. Then I just move development to the new repo. The new project layout can be completely different, but Git blame works and I’m happy with that.

cole_ - 3 hours ago

We used Copybara to setup a hub-and-spoke model at Dagster where public-facing repos can live within our larger internal monorepo, and while it worked we had to do a lot of hacky things.

https://dagster.io/blog/monorepos-the-hub-and-spoke-model-an...

theodpHN - 11 hours ago

52+ years of progress... :-)

July, 2026: Google copybara allows one to move code between two prod repositories

March, 1974: IBM COPY allows one to move code between two prod partitioned data sets: OS/MVT and 0S/VS2 TSO Data Utilities COPY, FORMAT, LIST, MERGE User's Guide and Reference https://www.computinghistory.org.uk/downloads/8987

the_dude_ - 11 hours ago

If the only need you need is sync repos without exclusions or transformations I wouldn't bother, it could work for you until it doesn't when they archive it or kill it like kaniko or so many other google products/tools.

Gitlab has really simple way to mirror from Gitlab to Github or other git vendors/servers

- 4 hours ago
[deleted]
namanyayg - 18 hours ago

Nice, I built something similar ~5 years ago using nested git repos and scripts to accomplish a similar purpose of combined private and public repos.

My shell script definitely wasn't google scale tho!

DisagreeAndQuit - 2 hours ago

I work at Google and copybara workflows are the bane of my existence.

- 8 hours ago
[deleted]
nbobko - 9 hours ago

At my previous company we tried to use this tool to sync parts of the code between two different git repos. The tool turned out being unacceptably slow.

Handwritten bash scripts using git-replace and git-filter-repo [1] did a much better job

[1]: https://github.com/newren/git-filter-repo

alok-g - 15 hours ago

Interesting. Anyone knows how this compares to using git submodules and subtrees?

I had used those to create separate repo for website artifacts while the same also remain plugged into the webapp dev repo. (Both sides remain modifiable and changes mergeable to the other side.)

Thx.

xyzzy_plugh - 16 hours ago

Copybara is one of those things that you should have set up yesterday.

It works great and I've seen many teams gain significant productivity when collaborating in a monorepo with public bits.

If you're even toying with an internal monorepo you owe it to yourself to give it a try.

jumploops - 16 hours ago

We’re in the process of open-sourcing a few sub-projects within a monorepo, and didn’t know this existed!

I’m curious what downsides folks have experienced with this tool?

Any tips?

Gehinnn - 10 hours ago

Does this tool allow changes in both repositories? (with a 3 way merge strategy) git subtrees come close, but I have a use case where I need transformations/file filters on top.

ape4 - 4 hours ago

Why doesn't it have a capybara as its logo!

whirlwin - 8 hours ago

Does anyone know if it is useful for bidirectional sync between codeberg and GitHub?

theolivenbaum - 10 hours ago

Wild times when one can go from a HN post about an interesting open source code to a port to a new language in a matter of hours (wip, but almost complete: https://github.com/theolivenbaum/copybara)

neprotivo - 14 hours ago

If you are using Jujutsu you can achieve a basic way to maintain a public repo from a private monorepo with very little code and without Copybara. I wrote up how to do it here: https://vihren.dev/blog/20260625-jj-public-private-workflow/

bellowsgulch - 3 hours ago

I already shared git-fetch-file in another comment here, but the .git-remote-files manifests seem a lot nicer than whatever this thing does:

    [file "lib/util.py" from "https://github.com/example/tools.git"]
    commit = a1b2c3d4e5f6789abcdef0123456789abcdef01
    branch = master
    comment = Common utility function

    [file "config.json" from "https://github.com/example/tools.git"]
    commit = b2c3d4e5f6789abcdef0123456789abcdef012
    branch = master
    target = vendor
    comment = Configuration from tools repo

    [file "helper.js" from "https://github.com/another/project.git"]
    commit = c3d4e5f6789abcdef0123456789abcdef0123
    branch = main
    comment = Helper from another project
vs

    core.workflow(
        name = "default",
        origin = git.github_origin(
        url = "https://github.com/google/copybara.git",
        ref = "master",
        ),
        destination = git.destination(
            url = "file:///tmp/foo",
        ),

        # Copy everything but don't remove a README_INTERNAL.txt file if it exists.
        destination_files = glob(["third_party/copybara/**"], exclude = ["README_INTERNAL.txt"]),

        authoring = authoring.pass_thru("Default email <default@default.com>"),
        transformations = [
            core.replace(
                    before = "//third_party/bazel/bashunit",
                    after = "//another/path:bashunit",
                    paths = glob(["**/BUILD"])),
            core.move("", "third_party/copybara")
        ],
    )
There seems to be an absolute ton of reference at https://github.com/google/copybara/blob/master/docs/referenc..., whereas I feel like all the people using git-fetch-file just want files from other repos, and sometimes to make some changes on those.
willchen - 13 hours ago

i used this tool when i was at google, extremely helpful in open-sourcing things from google3 to github. still, i'm glad to just directly develop on github now :)

syngrog66 - 16 hours ago

That seems like a tool easily adoptable by folks engaging in dark patterns on GitHub, particularly the malware bait repos.

bellowsgulch - 4 hours ago

Reminds me of git fetch-file.

“Fetch and sync individual files or globs from other Git repositories, with commit tracking and local-change protection”

https://github.com/andrewmcwattersandco/git-fetch-file

- 4 hours ago
[deleted]
lysace - 18 hours ago

Cute name. (Naming is hard and important.)

yahavthehackern - 8 hours ago

[flagged]

Srikann - 7 hours ago

[flagged]

shizuhalabsai - 14 hours ago

[flagged]

krick - 8 hours ago

I get it that there are use-cases for this, but it's surprising to learn that apparently use-case space is big enough for it to invite a creation of a dedicated tool. I mean that the fact you need it is a bit shameful on its own, no? Usually, when you need to reuse the code between the projects, you try to extract it as a separate library / module. The copying between repos is just a lazy solution, because "ain't nobody got time for that".