0

I have a project which source code is being hosted in SVN. I want to push it to github in order to have a better younglings' commits reviewing capabilities. While also keeping a single folder which is tracked by SVN and git (no patches).

On my local machine i've checked out fresh copy from SVN, initialized git repository and pushed it to remote.

How can other developers initialize a git repository in existing folder so their local repository acts as if it were cloned from a remote?

What have I tried (based on multiple SO answers) is this:

$ cd local_svn_working_copy
$ git init .
$ git add .
$ git commit -m "tmp"
$ git remote add origin git@github...
$ git pull --allow-unrelated-histories

And it all seemed to work fine until I created a new branch (with git checkout -b new-branch), pushed it to remote and started to fill out a merge request. because my merge request included:

  1. my initial commit "tmp"
  2. merge of main and origin/main branch
  3. my local changes which were made in current branch

Which doesn't seem right, because what I expected to see in only my local changes. What is the proper strategy?

2 Answers 2

1

I'd do the following:

cd local_svn_working_copy
git init
git remote add origin https://github...yadda.yadda...
git fetch origin
git reset origin/main  # NOT --hard!

At this point, git status will report whether my local state differs in any way from the current state on Github.

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

Comments

1

When you create a new local commit every time, it is a completely new unique commit because of the timestamp. You can't do it that way.

You can download only .git folder contents by running the following command in the local_svn_working_copy folder

mkdir .git
git clone --mirror git@github... .git

and remove bare=true line from .git/config file.

2 Comments

Thank you very much! Your solution works well, but feels a little bit hackish :) (the need to delete a bare=true)
Yes I agree, it is a dirty hack. @j6t solution is better.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.