Tech 101: Get Started with Git

Today, your goal is to get up and running with Git. You ready?

Git is one of the most popular version control systems and is quickly gaining prominence. It is used on multiple cloud hosting services, including Amazon’s EC2 and Heroku, and has vibrant usage among top open source communities.

Which means that if you want to make use of Amazon or Heroku’s awesome server power or contribute your code to an open source project, you have to know how to participate by using git.

How Git works

Git is an open-source version control system (meaning, it’s free!) that allows developers to track changes made on their code files throughout the lifetime of a project. Git is designed such that it views your code files like a “tree” and allows you to do cool things like create a “branch” where you work on some of the files without affecting the “trunk” code base until you are sufficiently convinced that the changes you are making are good and won’t break the rest of the tree.

If you are alone working on a project git is a great way to track the changes you make and also safeguard yourself from making a silly mistake that breaks your web app or, worse yet, accidentally delete months of work.

Where Git really excels, however, is for projects where more than one developer is working on the code. The tree-like architecture we described above allows many developers (up to hundreds!) to work on a project at the same time without the code devolving into one big hairy mess.

Git was initially created by Linus Torvalds to be used on Linux kernel development with a large, distributed team of developers. Since the Linux kernel project is very large and the development was distributed among developers all over the world, Torvalds designed Git so that it would be fast and good at distributed version control. The beauty of Git is that it allows developers to easily merge changes into the master code base and encourages developers to be experimental, because Git allows you to make changes locally and not have to push to a centralized repository until you are ready.

How is Git different from other version control systems?
Git is a great version control tool because it’s lightweight and straightforward to use, and it provides incredible compression and speed.

Since Git is so popular, and the Git community is so robust, thanks in large part to the popularity of Github, learning Git is one of the best things you can do in your process of learning development.

How to Get Started with Git

Once you start working with Git on your computer, then you can do fun things like join Github and start to collaborate with other Git-ers. Look out for more info on all that fun stuff coming on Friday.

Step 1: Install Git

Git has a fantastic guide all about how to get up and running with Git. In order to install Git you are going to need to use your command line (or terminal) tool. Before you dive into Git, review the key command line commands.

The key to using the command line is that you are going to be speaking to your computer directly with some very specific language. The good news is that when you write the wrong thing your command line will tell you and the other good news is that the Git install guide tells you exactly what to write.

Go get ‘em: Getting Started Installing Git

Step 2: Learn the top Git commands you gotta know

Using Git is actually quite easy, as long as you type the right thing. You are quickly going to find that there are really only ten or so commands that you are going to find yourself using 90% of the time. And here they are!

Once you have created the directory (folder) for your code and you are inside of that directory in the command line, try typing the follow commands:

git init
This command will create a git repository so you can get started!

git add .
This command is used to stage all of your changes, which means that you alert Git to the fact that you have made changes.

git commit -m “Your commit message”
This command tells Git that you have made changes and in between the quotes is where you tell Git what you did.

git push
When you are ready to share your changes with others, git push pushes the changes to a remote branch such as Github or a cloud hosting service for deployment.

git status
This command will provide you with information on the current state. You can see what files have been added, which are untracked, which are staged and which branch you are working on.

git diff
Before you stage and commit, this command will show you what you’ve changed in the repository. It is very useful for a sanity check before you commit your changes.

More good Git learning tools

Try Git
A great interactive Git learning tool made by Github and the Code School geniuses.

Jane Wang

Jane Wang is a Mobile Software Engineer at Etsy, an alumni of Hacker School, and formerly a product manager and an investment banker. She writes about mobile, technological trends, and coding at Forbes, Women2.0 and TechWomen, speaks at schools and conferences, and makes things with brackets, numbers, and paint. Follow her on twitter at @janeylwang and read more of her writing at Isometric Cube.