David Ruttka

I make computers do things

Git for Windows and .NET Developers Part 2 Advanced Tools and Options

If you followed my last post, you’ve got Git installed. You can initialize and commit to a repository. What now?

posh-git

You could constantly type git branch to see which one you’re on, and git status to see how many adds / mods / deletes you have, like this:

image

Alternatively, you could just see those bits of information in your prompt:

image

This magic comes from posh-git, and here’s the way I got it installed. These are just about the same instructions as on the github page linked above, but I make a few assumptions. For example, you’re using a decent version of Powershell and you added Git to your path as instructed in my last post.

1
2
3
git clone https://github.com/dahlbyk/posh-git.git
Set-ExecutionPolicy RemoteSigned
.\posh-git\install.ps1

What does this do?

  1. First we get the code. We’ll talk more about git clone later.
  2. Next we set an execution policy. This might already be set. You could use Get-ExecutionPolicy to find out, but a set is quicker than a check plus a set.
  3. Finally we run the install script that is in the directory that git clone created.

If you still have that “demo” dir/repo we created last time, you can cd into it, change some files, and see the fruits of our labor!

.gitignore

If you’ve been using TFS, SVN, Fortress, or Visual SourceSafe, you’ve probably become accustomed to Visual Studio deciding what goes into source control and what doesn’t. Add a file to the project? That’s included. Build? Those binaries are not.

Git is file system based, which means if it’s a file, it’s included. How can we prevent junk from getting into our repository? Tell Git to ignore what doesn’t belong!

I can’t take credit for the most awesome .gitignore file I’ve seen. That belongs to Madhi Taghizadeh, and you can get it here.

Note that I’ve been using this handy dandy trick to make projects automatically restore NuGet packages before each build. If you do this as well, you probably want to kill the two negations at the bottom of the file that tell Git to include NuGet package DLLs.

image

gitflow

You may not fully appreciate this one until we talk about branching, merging, and the strategies surrounding this topic, but let’s get it setup anyway. You can wait and do this later (after you’ve seen why you’ll want it), or you can trust me and get this out of the way Winking smile

First, we need to collect two dependencies that gitflow utilizes.

Now, from the command line

1
2
3
git clone --recursive https://github.com/nvie/gitflow.git
cd gitflow
contrib\msysgit-install.cmd

So what does this do?

  1. First, get some code again. Do not forget the –recursive flag!
  2. Change to the gitflow directory that git clone just created
  3. Run the installation

What’s Next?

Like I said, what gitflow does and why you’ll want it will come into play later, as we explore some of the more popular branching strategies in the Git universe. In the next post, we’ll learn how Git differs from SVN, TFS (or heaven forbid Visual SourceSafe), and take a look at the strategy upon which gitflow was based.

Sneak Peek

Alright…if you’re already familiar with Git but not with gitflow, check this out.

image

This post originally appeared on The DevStop.