For those of you that are new to development, maintaining your project with Version Control is the industry standard and Git is the Version Control Standard.
What is Version Control
Version Control refers to the management of changes to documents, computer programs, large web sites, and other collections of information
Essentially Version Control systems such as git allow you to keep a detailed log of every change to your project including who made it and when it was made. This has endless utility as you can easily:
- Peel back to a time you knew your project was working
- Check to see who wrote the code you’re looking at
- Allow multiple people to edit the same files without worrying about conflict
- So many more things!
So, now that you know you need git, let’s figure out how to get git installed!
Often times git is already installed on your computer. To check if it is, just fire up your favorite terminal and type:
If you get a version number, you’re all set! If not, keep reading this section!
Git is one of the few open source linux programs with a beautiful and easy to understand website. I highly recommend checking out the installing git article on their home page.
Essentially it boils down to git being pre-installed on almost every Mac and Linux distribution. If it’s not already installed you’ll be able to be install it with most any package manager.
Now that we have git installed. Let’s cover some basic usage. There are really only three commands you need to know about when starting to use git.
First, let’s use that sweet terminal to move into a folder where you currently have some code you’ve been working on!
Command #1 – git init
The first thing we need to do is initialize this project. This is essentially just telling git that you want to consider the current folder a project that you plan on doing sweet Version Control inside of.
Command #2 – git add
This took a minute for me to understand. Just because you have git initialized in the current folder doesn’t mean that git is ‘tracking’ your files. Tracking is the word within the git community that means actively checking for changes.
The simplest thing to do here is tell git to just track every file in your folder.
git add .
Command #3 – git commit
The last thing you really need to know in order to use git is when and how to make a ‘snapshot’. A snapshot is the git term for when you decide a moment in time deserves its own save spot. You should take these snapshots often as the more you have and the better they are labeled the easier time you’ll have jumping back and forth in your code history.
To take a snapshot and give it a message you can just:
git commit -m 'A description of what has been done since my last commit'
Take a deep breath!
You made it through! That wasn’t so bad was it?
From here you can start keeping a good record of your project. I like to make a commit after every task I do on my code base. For example:
- Added new icons
- Fixed the log-in bug
- Added new column to database
- Changed the sidebar width
Some other fun commands
Now that you’re well on your way to becoming an expert, here are some other cool tools git comes with out of the box!
Show a log of commits
Show the specifics of a commit
Grab one of those unique SHA’s from git log and run
git show SHA
See what you’ve changed since the last commit
More to Come
Be sure to stay tuned as we’ll talk a lot more about things like:
- Taking git online
See you next time!