Using Git Inside of TFVC

June 12, 2019    Development Process Git TFVC

Using Git inside of TFVC

I’ve written about how I “ like git over TFVC ” recently. We can’t always change things and it’s not always wise to do so. I’ve found that I can still use Git locally to have the goodies of Git (a history of commits, branches, stashing, fast switching between branches). This is especially useful for long running changesets (I know you’re not supposed to have those, but you can’t change everything).

I used this successfully for a long lived changeset. TFVC seems to be tied (I’m making a broad assumption) to processes that require Dev/Main/RC branching and promotes one changeset per branch to make the merging easier later. I worked on the same thing for a month! I only used master in git. The small commits helped me stay on track, gave me some freedom to experiment and go back. I was easily able to see what I pulled in with get latest. I also could make a small experimental branch to test things out.

I attempted using Git inside of TFVC for a couple hour bug fix and it was not worth it. You can read what I tried below.

Update: 4/29/2020. I recommend git tfs over my approach below. However, I was unable to get the check-in tool to work. The recommendation was to install Visual Studio 2015. I didn’t do that, but it’s easy to create a shelveset with git tfs shelve 'xyz' and finish the check in with VS and TFVC.

Getting Started

Use your favorite command line tool and start the git repo. I like Cmder , but the Windows CLI is going to be really cool soon . I’m assuming you already have Git installed.

git init

git status will show you have a repo running.

In File Explorer you’ll now have a new .git folder.

Add all the files to master using git add . and git commit -m "init".

Opening the Solution - VS gets a bit confused

TFVC shelve failed

Click No.

My Experiment for a quick bug fix

Development Time - Don’t use branches

I wanted it to work with branches, but soon found out it is too much trouble.

If you wanted to do it, here’s what I tried out and found

Create a branch and check it out with git checkout -b <branch-name>.

Now use Git as normal with small commits.

Create a TFVC shelveset at the end of the day. This will help you make sure you’re getting all the right files marked in TFVC for add/remove/rename/delete, etc.

Interruptions - Don’t use branches

Interruptions happen all the time. You’ll also need to do a Code Review and it may take awhile for the team to give you feedback. If you switch your branch back to master, the Visual Studio TFVC pending changes will still show those as pending. So you’ll still want to need to use Suspend Changes :-(.

You will need to commit or stash your changes.

git checkout master.

Suspend your changes in Visual Studio, My Work.

Resuming - Don’t use branches

Get Latest in Visual Studio.

Commit to master. git add ., git commit -m "got latest"

git checkout <branch-name>

git rebase master

Click Resume in My Work of Visual Studio. Then, you’ll get merge conflicts. Click Keep Local File Contents (since you’ve already gotten them from Git).

Lesson: Git doesn't get us much in this situation and actually makes it more complicated :-(.

Using Git-TFs

The git-tfs tool may be what you want to try out. “git-tfs is a two-way bridge between TFS (Team Foundation Server) and git, similar to git-svn. It fetches TFS commits into a git repository, and lets you push your updates back to TFS.” I may come back here and add what I learned trying that out.

I worked with a guy who used git-tfs for a couple of months while the company did training and got people ready to move to Git. He became the Git Guru and helped me out of several Git messes as I was learning.

choco install gittfs

In a Migrating from TFVC to Git talk, he shows migrating then talks about Git-TFS (minute 5 and on).

Hints

  • Treat master as what’s in TFVC
  • Just work in master, don’t use branches for each work item
  • Use Git’s small and often commits
  • Branches may be useful for experimenting and easy to go back
  • Shelve Often, check TFVC Often
    • Catch renamed, missing, deleted files. TFVC will tell you what’s wrong.
  • Use TFVC Source Control Explorer and Visual Studio to make sure files are getting marked as changes in TFVC.
  • Check out my article Some Git Help
  • VS Code has a nice Git GUI
    • as an alternative, GitHub client is a nice GUI, if you don’t want to do it all in the Command Line
      • Normally, I’d use Visual Studio, but it gets confused when you have a .git folder and TFVC as your source provider.

Pros

  • You can see what was retrieved with Get Latest
    • I will get latest in VS, then look at the new changes in Git, then commit those as git commit -m "got latest".
  • Small commits give you a place to go back to and see your progress
  • Helpful for long lived and large changesets

Cons

  • We still have to use Suspend Changes, even though we have branches now.
  • Branches don’t help
  • Visual Studio gets confused.

Conclusion

Sometimes (for various reasons) you can’t just move your team to Git . You can use Git, but don’t get the benefit of branches (without a lot of trouble).



Watch the Story for Good News
I gladly accept BTC Lightning Network tips at [email protected]

Please consider using Brave and adding me to your BAT payment ledger. Then you won't have to see ads! (when I get to $100 in Google Ads for a payout, I pledge to turn off ads)

Use Brave

Also check out my Resources Page for referrals that would help me.


Swan logo
Use Swan Bitcoin to onramp with low fees and automatic daily cost averaging and get $10 in BTC when you sign up.