I have to migrate the code from TFS to Azure DevOpsService Git repository. For that, I am using "git-tfs". The cloning of tfs code using "tfs-git" is ok. However, when I tried to push the code to remote origin, I am facing the issue. I tried the following approaches -
- In an empty folder, I did
git init, thengit clone <remote Git>. After that, I rangit tfs clone <TFS-url> <TFS folder. I removed the traces of "Config" and "Description" files inside.git/repository (just removed the references of . When I tried to push the code by executinggit remote add origin <remote Git Url>andgit push –u origin –-all, I got the error likeOuter clone contains inned clone. Do you want to create submodule?I can understand that because in the folder, cloned from TFS, there is already a '.git' folder. Instead of that, I tried normalgit add .,git commitandgit push, I got the response as "everything is up-to-date" but nothing is really pushed to remote origin. - Second, I tried with another empty folder. I did
git initbut did not clone from the remote origin. Then I cloned the TFS code from TFS server using "git-tfs". This time, there was no 'outer clone', so I thought everything would be smooth. However, as I didgit init, so there was a.gitfolder already created. Again, I got the same error. - I tried again by taking a fresh directory. I did not do
git init. I even cloned the TFS code in a different directory and then copied to the empty directory. After setting the origin, when I executedgit push –u origin –-all, I got the message thatUpdates were rejected because the tip of your current branch is behind. Use git pull before pushing again.When I triedget pull, I got the message,fatal:regusing to merge unrelated histories. How to fix the issue ?
As you mentioned, the problem is that there is already a
'.git'folder in the repository. There's aconfigfile in the'.git'folder which defines the version control information (includes the original remote repo there) initialized by the git-tfs tool.So, we need to remove the original remote repo and other
git-tfssettings from theconfigfile first, then rungit remote add origin <remote Git Url>to set the new git remote.Try to follow below steps to do that:
Create a directory where TFS code to be migrated to (
git-tfs-demo-repoin below sample).Open terminal in administrative privilege and cd to the newly created directory in terminal.
Run below command to clone the TFS repo
git tfs clone https://{server-Name}/{Collection} $/ProjectName/xxA new repo is created in the directory (
TFVCrepo for example here).Open
configfile with any text editor from directory.gitof newly created repository directory. The originalconfigfile should like this:Remove all sections except the
[core]section from theconfigfile, then save it. So, theconfigfile would look like this:Run below commands to set git remote and push to remote repo.
git remote add origin <remote Git Url>git push –u origin –-allOnce completed, we can see the
configfile changed to look like this: (version control is changed to the new remote repo)Screenshot for your reference: