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:
- my initial commit "tmp"
- merge of main and origin/main branch
- 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?
CodePudding user response:
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.
CodePudding user response:
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.