18 Apr 2011

.gitconfig

No Comments Uncategorized

I have been using GIT for about a year now, and over the last year I have configured some things in GIT that make my life as a developer much easier.  This post is going to show you my .gitconfig and hopefully accelerate your own configurations of GIT.

Finding the .gitconfig file

Note: all of this below assumes you are using msysgit. If your are not using msysgit, your mileage may vary.

The first thing you need to do is find your .gitconfig file.  By default it is installed in the root of your Windows user profile. To get started lets open it up in notepad, by running the following command after pressing [Windows Key] + R.

notepad.exe %userprofile%/.gitconfig

The first thing you will probably see is any configurations you have made through the command line to set your name and email and anything else you have done using the “git config” command.

My .gitconfig

2011-4-21: I updated the configuration below to include comments and some extra parameters for beyond compare that label the merge section windows.

; user identification
[user]
    name = /* Your Name Here */
    email = /* Your Email Here */
[github]
    user = /* GitHub User Name */
    token = /* GitHub Token https://github.com/account#admin_bucket */

; customizations
[alias]
	unstage = reset HEAD
	hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short

; environment
[core]
	symlinks = false
	autocrlf = true
[color]
	diff = auto
	status = auto
	branch = auto
	interactive = true
[http]
	postBuffer = 52428800
[pack]
	packSizeLimit = 2g
	
; diff and merge
[diff]
	tool = beyondcompare
	guitool = beyondcompare
[difftool]
	prompt = false
[merge]
	tool = beyondcompare
[mergetool]
	keepBackup = false
	prompt = false
	
# 
# beyond compare
# http://www.scootersoftware.com/
#
[difftool "beyondcompare"]
	path = /c/development/tools/beyondcompare/
	cmd = /c/development/tools/beyondcompare/bcomp.exe \"$LOCAL\" \"$REMOTE\" -nobackups -title1=\"Old Version\" -title2=\"New Version\"
	trustExitCode = false
[mergetool "beyondcompare"]
	path = /c/development/tools/beyondcompare/
	cmd = /c/development/tools/beyondcompare/bcomp.exe \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\" -nobackups -title1=\"Local Changes\" -title2=\"Remote Changes\" -title3=\"Committed\"
	trustExitCode = false
	
#
# diff merge
# http://www.sourcegear.com/diffmerge/
#
[difftool "diffmerge"]
	path = /c/development/tools/diffmerge/
	cmd = /c/development/tools/diffmerge/diffmerge.exe --nosplash --title1=\"Old Version\" --title2=\"New Version\" \"$LOCAL\" \"$REMOTE\"
	trustExitCode = false
[mergetool "diffmerge"]
	path = /c/development/tools/diffmerge/
	cmd = /c/development/tools/diffmerge/diffmerge.exe --nosplash --merge --result=\"$MERGED\" --title1=\"Local Changes\" --title2=\"Merged: $MERGED\" --title3=\"Remote Changes\" \"$LOCAL\" \"$BASE\" \"$REMOTE\"
	trustExitCode = false

My Diff and Merge Tools

I have my config setup to use beyond compare but I also have included diff merge for anybody who doesn’t have or doesn’t want to spend on beyond compare. Note: you will need to customize the paths for beyond compare and diff merge, since your paths will probably differ from mine.

My Alias’s

I have a couple alias’s that I use all the time, that make working with the command line interface easier. Try them out after you update your .gitconfig file.

Unstaging Changes

git unstage

History

git hist

Conclusion

So that is my .gitconfig file, it is basic and does exactly what I need to accomplish 99% of my daily programming tasks. I encourage you to customize yours and keep it in a cherished place like you do with your Visual Studio config files, Resharper config files, and any other productivity tools you use on a daily basis.

Please share your configurations that you cannot live with out below in the comments.

17 Mar 2011

Adding Git Command Line To Visual Studio

14 Comments Uncategorized

If you are an avid Git user like I am, but also happen to work in a Visual Studio environment, you know that getting to your Git Bash command prompt is anything but easy. My typical process looks probably something like yours:

  1. Open Visual Studio
  2. Open your project you are working on
  3. Right click on a folder in the project and choose “Open Folder in Windows Explorer”
  4. Back your way up through the folders in Windows Explorer till you get to the parent folder that is the root of your project. 
  5. Then right click on the root folder of your project and choose “Git Bash Here”
  6. Start using Git Bash

To me this process got so annoying and tedious that I finally decided to explorer other options to get to my Git Bash prompt. The best one that I have come up with so far and works perfectly for me is adding the Git Bash as an “External Tool” in Visual Studio.  To get started you will need a couple of things:

Adding Git Bash Prompt

The first thing we need to do is to add Git to our external tools in Visual Studio.  To do this we need to first open up the “External Tools” screen which is located under Tools > External Tools… in Visual Studio.

When the screen is open you are going to want to click the “Add” button and fill in the values to look like the screen shot below:

image

note: that I am running this from a 64-bit install of Windows 7, if you are using a 32-bit install your Program Files directory will not have the “ (x86)” on the end.

You will now find a new menu item under the Tools menu called Git Bash.  This will launch the Git Bash command prompt for your current solution when selected.

Setting Up A Keyboard Shortcut

If you are anything like me you will prefer a keyboard shortcut for opening up the Git Bash command prompt. To setup the shortcut we need to first open up the “Options” screen which is located under Tools > Options in Visual Studio. Then choose Keyboard from the Environment section.

In the Show commands containing text box enter the following in to the text box “Tools.ExternalCommand2” and then in the Press shortcut keys text box press the corresponding keyboard shortcut that you want assigned.  (I choose CTRL+0)  Then press the “Assign” button and then the “OK” button to exit the “Options” screen.

image

tl;dr

Hopefully this will be helpful to everybody who has the same affection for Git and Visual Studio as I do.

21 May 2010

6 Git Commands To Get You Started

No Comments Uncategorized

I have heard a lot of chatter on blogs and twitter about how people just don’t get git.  They exclaim it is too hard to learn, too hard to work with, doesn’t make sense, and on and on…  To put this bluntly, I think they are just complaining for the sake of complaining, or at the very least they never bothered to learn how to use git.  So as a remedy to this, I am publishing the only 6 git commands that you really need to know to get yourself started for a project where you are the sole-developer.

git init

Used to initialize the current directory as your local repository for your projects source control.

git init

git remote

Sets the remote, or online, repository that you want to commit your local repository to.

git remote add origin {{git-url}}

git add

Used to add files to be committed.  To add a single file do this:

git add {{filename}}

Or to add all the files in the current directory and all subdirectories, do this:

git add .

git commit

Used to commit the current changes to your local repository. 

git commit -am "your message about what changed and why"

git status

Used to show the differences between what has been committed and the current directory.

git status

git push

Used to push your local repository, or in other words your committed changes, to your online repository such as GitHub.

git push

Does the same thing as the above.

git push origin

Does the same thing as above assuming you are in the master branch, which is default for new Git repositories.

git push origin master

Bring in all together

Now lets bring all these commands together as an example of how they might be used in a simplistic, but real world situation.

git init
touch README
{{ Add Some Test To Your README File }}
git add README
git commit -am "adding the readme file to my project."
git status
git remote add origin git@github.com:managedfusion/coderjournal.git
git push origin master

Hope this helps you get started with Git. If you are interested in some of the more advanced ways of working with Git there is an excellent tutorial put together by GitHub at http://learn.github.com/.  Also don’t forget to setup your .gitignore file.  Happy coding.