TransWikia.com

Do i need to git checkout a remote branch created from a svn conversion before pushing to github

Stack Overflow Asked by serverSentinel on December 9, 2021

I’m converting a 10GB svn repo to a private github.com repo. The git svn clone command worked and left me with 66 remote branches, 10 of which I need to maintain and sync to github until we can complete the cutover.

What do I need to do to push the git repo to github including those 10 specific branches?

Github has said I cannot push the repo with one push because of how large it is. They said to use git log, pick a sha and push them in batches like this.

git log --pretty=oneline 
git push <remotename> <commit SHA>:<remotebranchname>

Since that syntax appears to be picking out specific commits by their sha code how do I ensure branches get pushed as well?

After I complete this initial refspec push dance, will the standard git svn --fetch all followed by git push --all maintain this repo?

2 Answers

In the end this is what I had to do.

  1. git svn clone --prefix "svn/" -s https://path/to/svn/project project
  2. Create project in GitHub; add each of the branches.
  3. For each branch: git branch %branch_name% svn/refs/%branch_name%
  4. git remote add github https://github.com/.../project.git
  5. git push github %sha:master
  6. git config push.default.matching
  7. git push github --all

Step 5 had to be repeated about 8 times, each time I picked a sha closer to the HEAD of the repo. This accomplished pushing almost all my repo so i was able to git push --all to finish off the rest of the branches.

Synchronizing is more difficult:

  1. git checkout master
  2. git svn rebase
  3. git checkout %branch1
  4. git svn rebase --local
  5. Repeat steps 3 and 4 for each branch you're syncing
  6. git push github --all

Answered by serverSentinel on December 9, 2021

It's been years since I used git-svn, so please bear with me for untested answers.

Svn branches are notoriously free-form: everyone's got their own uniquely-creative idea of how to structure the {trunk,tag/,branch/} namespace. To a git-svn user, this typically means that they have to configure the branch mapping, by hand, in .git/config.

So, given a setup somewhat like this:

[svn-remote "the-svn-repo"]
url = [...]
fetch = subproject-A/trunk:refs/remotes/svn-subproject-A/trunk
fetch = subproject-A/branches/*:refs/remotes/svn-subproject-A/branches/*
branches = subproject-A/trunk:refs/remotes/svn-subproject-A/trunk
branches = subproject-A/branches/*:refs/remotes/svn-subproject-Aa/branches/*

— you'd have the subproject-A svn branches mapped to git branches in git branches -avv.

You should vividly understand that in git, branches are really not much more than named refs (pointers to commits' SHA1).

... how do I ensure branches get pushed as well?

— by ensuring that 1) the commit objects got pushed, 2) the 10 refs on github remote got updated to point to the same commits that your local 10 refs point to (which in turn, should be the fresh git-svn imported commits).

There's a lot of confusion to be had, until you understand schematically what git is doing, by absorbing its data model. One exercise I highly recommend: using git remote add and git remote set-url, configure remote names which make sense to you. Don't use origin. Name the remote for the GH private repo as github; name the svn-remote as my-svn or whatever. It'll help you keep track of what you're doing and reduce confusion.

As soon as you set up the 10 branches you care for as local branches in git, and configure their push.default in .git/config, git push --all will do what you want.

... will the standard git svn --fetch all followed by git push --all maintain this repo?

This is certainly doable; but abandon all hope to do it confidently without learning a great deal of how git works.

To answer the title question:

Do I need to git checkout a remote branch created from an svn conversion before pushing to github

No, I don't think so. It's rarely (never?..) necessary to checkout remote branches. Usually, you check them out by making a local branch which tracks the remote branch as its upstream, then git checkout the local branch.

Additionally, git push supports explicitly specifying what you what to push and where to (completely disregarding the state of HEAD). Like this:

# Push local branch trunk to remote "github" as remote-renamed-trunk
$ git push github trunk:remote-renamed-trunk

# Push remote branch "one" to remote "github" with a name containing '/'
$ git push github subproject-A/branches/one:subproject-A/one

# ... etc

Answered by ulidtko on December 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP