Welcome To Git

What is Git?

Git is a Version Control System. When you start a project it develops and changes as it grows. Adding, changing and deleting files can get messy and complicated, especially if more than one person is involved.

Put simply, Git keeps track of the changes you make.

When you create a folder for a project, you tell Git that the folder is a project, and git keeps an eye on the folder. When you make changes to the project folder you type in a Git command and Git records the changes.

 

What is the point in that?

If you only had one file, and you only ever added to the file, and when the file was finished you saved it, handed it over to the client and got paid, then Git would be pointless. But we all know that's not how it works.

 

Here's a scenario

You are in a team of three people, all working on one website, which has a few hundred files in a load of folders.

You have one shared folder for this project and you can each access and edit it, maybe it's on a local network or in the cloud.

Everything is going fine until you go to edit a file and the file has changed, the code in it is not what you expect. So you send emails to the others in your team and ask who changed it.

Maybe they remember editing the file, maybe they don't, maybe they remember the changes in detail and maybe they don't. Maybe they deleted a file completely because they had an idea to take the project in a different direction, maybe they messed up and deleted a folder representing hours of hard work. Hopefully you backed up right?

Enter Git.

 

You get a copy…. And you get a copy…. And you get a copy!

With Git there is the one shared folder, called a repository, accessed by everyone, but you don't just bust into it and start messing with the files. No with Git you copy the whole thing and save it as your own folder, your own clone of the project.

So now you have your own local copy of the files, you can change them about as much as you like. What’s better is that when you make changes to your local copy, you can then upload the changes back to the master along with a note of what changes you made, lest you forget.

After you upload your changes to the master folder, everyone else can download the folder, and get your changes, Git will tell them what is different and they have the option to keep their copy as it was or merge their version with the new master version.

 

Git has Branches everywhere

What if you want to take the project in a different direction? You have some changes you want to make, but you don’t want to merge them with the master project folder.

Git lets you create another copy of the project folder and files which can be changed to your heart’s content. Git calls this copy a Branch, as in the main project is a tree trunk, and you branch off it with another version which is going to be slightly different.

You can create a branch, with its own files, make a load of changes and upload the new branch to the repository for everyone to see it. Just like the master project folder, the branch can be copied by everyone and they can then change their own copy too.

A branch is a great way to play with your project, maybe you delete the branch after you have messed around with it, or maybe you like the changes you have made and you merge the branch back into the master folder.

Maybe the branch becomes a new project in its own right, often software is branched and both versions continue in separate development and are presented as different software packages.

 

Something to note

Every change you make prompts Git to bring up the log . The log must have a comment added to it every time you want to add a change, in fact, if you don't add a comment, Git wont even let you add the change.

Why the strict rules? Because Git is all about keeping track of changes. Git makes sure that every change is mentioned so in 6 months you don’t have to wonder what the hell you were thinking when you changed all the variable names in a JavaScript file to _banana.

 

The files, they are a’changing

So you have a perfect record, including of the great big mistakes you made, not great right? If only you could take those mistakes back and pretend they never happened. Thanks to your comments in the log, the whole team know it was you who changed all those variable names and now nothing works.

Git to the rescue again! Each time you commit some file changes to the project, you not only write your comment, but Git saves a record of what the files used to look like too. So if two commits ago you ballsed the whole thing up and never realised, you can just ask Git to turn back time to a working version of the project.

 

What did I just read?

  • Git is a Version Control System – Tracking your projects, and the changes you make to them

  • Everyone gets their own copy (or Clone) of the project repository folder to change

  • Projects can be branched and then merged back if required

  • Every change to the project repository is accompanied by a note in the change log

  • Changes can be rolled back to previous versions

 

Tags

git
version control system
introduction
basics

Add new comment

CAPTCHA
Answer the below question to help us fight spam

What is 2 + 2?