There might be many reasons for you or your organization to migrate your old repositories in TFVC to Git and you would like the keep the history of the check-ins/commits, here I will explain two ways of achieving this.

  1. Migrating using git-tfs, with this you can migrate with full history and it is a little complex process.
  2. Migrating using Import repository wizard in Azure DevOps, with this you can migrate with 180 days history and it is a very simple process.

In my case, I had to choose option 1 as my project was older than 4 years and I wanted to get the history for it.
image

1. Migrating using git-tfs

Get git-tfs by following the instructions mentioned at git-tfs/README.md, I installed it through Chocolatey which I already had installed, chocolatey is a nice and easy way to install and upgrade software/programs/packages on windows, do check it out if you haven't used it yet, it is a package manager for windows.

  1. Run cmd as administrator
  2. Install git-tfs by running choco install gittfs
  3. Verify if git-tfs is installed correctly by running git-tfs --version
  4. You should see its version information like below
    C:\WINDOWS\system32>git-tfs --version
    Found matching Visual Studio version at C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional
    git-tfs version 0.32.0.0 (TFS client library 16.0.0.0 (MS)) (64-bit)
    
    Note: If you want to force git-tfs to use another version of the tfs client library,
    set the environment variable `GIT_TFS_CLIENT` with the wished version (ie: '2015' for Visual Studio 2015,...)
    Supported version: 2019, 2017, 2015
  5. Run the command  git tfs clone [URL] [TFVS_Project] “[Local_Git_folder]” after changing placeholder values of URL, TFVS_Project, Local_Git_folder. In my case it was like below:
    C:\WINDOWS\system32>git tfs clone https://arunendapally.visualstudio.com/defaultcollection/ $/donna-bot "C:\Arun\Project\donna-bot-new"
    and after you hit the enter key, it will prompt you to login
    image
  6. This process will take a while to get everything cloned into the local git folder location you mentioned while running the command. You should see something like below
    image
  7. If you open the location in explorer you should see files cloned like below
    image
  8. If you want to see the git logs, you can run this command git log --all --oneline --decorate --graph and you would see something like below
    image
  9. Now you can open that folder in VS Code, clean-up any files you don't need, and add .gitignore for the files you want to exclude in the commit.
  10. Now set the git origin to the repository where you want to commit and push this project. You can run the below command replacing your git origin URL
    git remote add origin https://arunendapally.visualstudio.com/DefaultCollection/donna-bot/_git/donna-bot-new
    git push -u origin --all
  11. After running it I can it pushed all my changes to my remote with complete history
    image
  12. I hope you guys successfully migrated from TFVC to Git without any problem, if you are stuck, you can reach out to me, I can try to help.

2. Migrating using Import repository wizard in Azure DevOps

You can choose this option when you do not really care about the history greater than 180 days, and of course if you are not deleting the old TFVC repo, you can always get back to see the history.

As this is a simple approach you can simply follow these instructions Import repositories from TFVC to Git - Azure Repos | Microsoft Docs and you would be able to migrate from TFVC to Git repo with 180 days history.

That's it, please share this post with your friends and colleagues, if you liked it.

We would be working on companies repositories mostly but sometimes we would be working on personal git repositories as well. So ideally we would be setting user.name and user.email globally with our company username and email as shown below.

C:\>git config --global user.name "Arun Endapally"
C:\>git config --global user.email "arun.endapally@work.com"
C:\>git config --global user.name Arun Endapally
C:\>git config --global user.email arun.endapally@work.com

Whenever we clone a public repository or start our own personal repository, we would like to use our personal name and email instead of companies and it becomes very irritating for setting this information each time at the repository level as shown below.

C:\my-repo>git config user.name "Arun"
C:\my-repo>git config user.email "arun.endapally@personal.com"
C:\my-repo>git config user.name Arun
C:\my-repo>git config user.email arun.endapally@personal.com

We can simplify this process by setting this information at the folder level. First, create a separate folder where you want to clone the public repos or start your personal repo then open .gitconfig by entering .gitconfig in the run.

image_thumb1

In .gitconfig, update as below.

[user]
  email = arun.endapally@work.com
  name = Arun Endapally
[includeIf "gitdir/i:C:/Personal"]
   path = .gitconfig-personal

Note: You should add includeIf to bottom as highlighted in yellow, order is important here. Now create a file with name .gitconfig-personal in C:/Personal and add your personal name and email to it as below.

[user]
    name = Arun Endapally
    email = arun.endapally@personal.com

Now go ahead and test your setting, now you should see that the git repositories in the personal folder would use personal details while the rest of the folders would use work details and as below.

C:\personal>git config user.name
Arun Endapally

C:\personal>git config user.email
arun.endapally@personal.com

C:\personal>cd c:/work

c:\work>git config user.name
Arun Endapally

c:\work>git config user.email
arun.endapally@work.com

Enjoy! please share it with your friends and colleagues, if you liked it.