Thursday, 29 January 2015

Git and GitHub

What is Git?
Well, Git is not Github. Git is a piece of software that you install locally on your computer which handles 'version control' for you.

What is Version Control?
Let's say you have some new project, and you are planning to store all the files for that project in some new directory. You know that as time goes on, the files in this project will change - a lot. Things could get messy, and who knows when you might need to revert back to a previous working version of what you had?
So, you install Git on your computer. Then, you have Git create the new project directory for you. You also tell Git that you would like to keep a history of the changes you make within that directory.
Then, you add some files to kick off your project. The files you just added represent the first incremental step on the journey of your project. So you tell Git to take a snapshot.
Then you make a small change - your next incremental step. So you take another snapshot.
And that's about it for version control - make a small change, take a snapshot, make another small change, take a snapshot. You can then use Git to step back and forth whenever necessary through each snapshot (snapshot aka version) of your project directory. Hence, version control.

Collaborating with Git
That's great for you as an individual. But what if you are working on a team, and you want to share your project directory? And you want to make changes on your machine, send those changes to your collaborators, and also have changes they make appear in your machine's project directory?
Git is a so called distributed version control system. All that means is that Git has commands that allow you to push and pull your changes to other people's machines:
Collaborating using Git

Neither copy of the project directory is any better or 'greater' than any other - you are both collaborating on identical copies. This is a good thing, and Git gives you the power to work on your own copy as-is until you are ready to pull in your collaborator's changes, and push back your own changes.

Wouldn't it be great if there were a third identical copy you could both push and pull from?

Collaborating with Git and GitHub
Well, that's what Github is! At it's core, it's just a place to store your identical working directories - aka repositories, or repo's for short. That's the service that Github provides - it's literally a hub for Git repositories.
Collaborating using Git and GitHub
Git allows you to snapshot/commit incrementally, after each little change you do. I regularly have 10 commits per day, and I or anyone can cycle back and forth through those snapshots any time we like.

Alternatives to Github
Since Git and Github aren't really linked - Github is just another place to store identical repos - you could use any Git hosting service. One alternative is Bitbucket. This service gives you free private repos (unlike Github), in case you aren't ready to share your work with the world.
However Github is the most widely used Git hosting service, and has a broad community of users sharing code and interacting.

No comments:

Post a Comment