Gotta Get Git

Using .NET, PHP, or Ruby you probably should have your code somewhere nice and safe. These days there is no better place than Github. It is the place to start, maintain, and contribute to software projects or to even run your own private repositories or even setup some private repositories for a business. But enough about Github. In this blog entry I’m going to take a quick tour through getting Git and setting it up for basic use.

For Windows go check out msysgit.

For Ubuntu go check out git site.

For OS-X go check out these downloads.  This link also has information regarding how to setup and use the SSH keys. For Windows that will be extra work, since it doesn’t speak SSH very well. For Ubuntu, the instructions are pretty much exactly the same.

I also had a few tidbits about git in the past here and here. Simple apt-get installation instructions.

Once you have Git installed, there are a few things one should do right away.

A few things, once Git is installed that should be done include setting up your user name and e-mail address for commits. To do this follow these commands.

[sourcecode langauge=”bash”]
git config –global user.name "Your Name"
git config –global user.e-mail "blaghDblagh@yourdomain.com"
[/sourcecode]

You can also setup some aliases to commands that you’ll use a lot. I usually setup the following.

[sourcecode language=”bash”]
git config –global alias.co checkout
git config –global alias.c commit
git config –global alias.p push
git config –global alias.u pull
git config –global alias.a add
git config –global alias.s status
[/sourcecode]

Now that Git is setup and when a web project is ready we can commit and push. Navigate to the root of the folder structure where the project is and issue the initialization and following commands for Git.

[sourcecode language=”bash”]
git init
git add .gitignore
git commit -m ‘Adding the ignore file first.’
git add -A
git commit -m ‘Adding all subsequent files and the Ruby on Rails Project itself. In other words, first commit.’
git remote add origin git@github.com:Adron/somewhereOrAnother.git
git push origin master
[/sourcecode]

Note also this .gitignore file included in the overall project. This file is really important to pay attention to before any commits are made to the repository. If it doesn’t exist, and doesn’t have all of the files, directories, and other things that should be ignored, ignoring them after the fact is rather difficult. So make sure it is included and always has everything you want ignored. With Rails Projects this is placed by default, some Visual Studio tools will also add this, and other tools will too. However, it is safe to assume that it is not there and check.

The standard .gitignore included with Rails Projects looks like this.

[sourcecode language=”bash”]
.bundle
db/*.sqlite3
log/*.log
tmp/**/*
[/sourcecode]

For Rubymine and other exclusions I always add the following, and often times even more. It is easier to take something out and add it later, than it is to remove something after added.

[sourcecode language=”bash”]
#OS junk files
[Tt]humbs.db
*.DS_Store

#Webstorm & Rubymine files
*.idea
.idea
.idea/

#Rails Heroku and other bits to ignore
*.sqlite3
db/*.sqlite3
public/system/*
.bundle
log/*.log
tmp/**/*
tmp/*
doc/api
doc/app
*.swp
*~
.DS_Store
[/sourcecode]

Well, that’s all I got for now. 🙂 Cheers!

One thought on “Gotta Get Git

Comments are closed.