GENERAL

Think Like A Git, Commit Like A Boss: Light Introduction


Think like a Git, Commit Like a Boss is a series that’s focused on learning how to work efficiently with version control in your projects. Proficiency in working with Git is a key feature to been a  good and very effective programmer.

Why Should We Use Version Control?

Version Control is essentially for everyone. Most situations, we create, edit and save documents daily. The beauty of using version control is that it informs you about:

When you did it – It gives accurate information about the date and time you created/edited the documents.

Why you did it  – It also gives information about the reason behind the change you made.

History of Everything – There are times you erase the contents of a document ..maybe you had a new idea, or you were drunk during that period. Version control especially using Git gives the ability to see the history of everything you have done on that document right from when the document was created and it also gives you the ability to rollback to a specific change.

Easy Collaboration If you want to move fast, go alone. If you want to move far, go with others

During the course of your journey on earth ( I’m not a preacher btw ), you’ll work with a lot of people: good, bad or evil. You’ll work on projects together and the ability to manage changes to a project as more people get on the team becomes increasingly difficult. Version Control Using Git helps you effectively and painlessly keep track of people’s change on a project/document and everyone can easily be held accountable for their work on the project/document.

Let’s start with the Basics:

Note: Windows users, please download the git bash client here. Git comes pre-installed on Macs.

Whenever you are about to start any project at all, Use version control:

Let’s call our project  Git Education

First Step: Initialize Git

Open your terminal, create a directory called Git Education like so:

then move into the directory like so:

Now, we are in our working directory, let’s initialize Git like so:

it will show you a response message like “Initialized empty Git repository in …………….”

This creates a new subdirectory named .git ( hidden directory )  that will house all your files.

Second Step: Commit

Let’s create a file in our git-education like so:

..go ahead and open up that file in your Sublime or any other text editor and type this:

or you could write about anything you are interesting in currently and save the file.

Let’s check the status of our files now, from the terminal/command line…run this git command:

We should get something like this:

This simply means git doesn’t know about the file you have created yet!. Git is like “What the Hell is this?”. The file(s) git has no idea about are called Untracked files.

Now, let’s make Uncle Git know about our notes.txt file by running this command like so:

git add . simply means add all the untracked files to git

git commit -m “Initial commit” simply means let git know the reason why you are adding the file. You must supply a reason man!. Now, let’s run the git status command to know our status. You’ll be running that a lot, so make it your best friend.

It shows our tracked file. The next step is to push to a repository online. Do we have one yet?..No.

Let’s head over to GitHub and create a repository. If you don’t have an account yet, create one. Github helps host our files and repositories online, another alternative is Bitbucket. I prefer using Github.

I have created a new repository online. It’s empty at the moment. Now, run this commands:

https://github.com/busayo/git-education.git is the link to my repo, so replace that with yours.

origin is the default alias for a particular remote repository, you have the ability to name your own alias

so git remote add origin <repo_url> simply means “add the online store where we are going to push our files to”.

git push -u origin master – when you create a fresh repository, master is the default branch,…so it simply means push this local file to our online repository and -u means track and maintain upstream…to enable pulling and fetching latest changes from that branch anytime.

Note: Don’t feel overwhelmed if it seems there are lots of new names or terminologies you haven’t heard or come across before. It’s very simple, you don’t even need to cram it, once you work with it every day, it becomes a part of you that can’t be forgotten easily.

 

Below, is the file that I pushed..it’s now resident on my repository online!..Yaay!!! :smile:

 

 

We have barely scratched the surface, but this is a good start. There’s a lot more, stay tuned for more lessons as I teach you how to commit like a boss!

Please, let me know if you have any questions or thoughts about this in the comment section.

PROSPER OTEMUYIWA

About PROSPER OTEMUYIWA

Food Ninja, Code Slinger, Technical Trainer, Accidental Writer, Open Source Advocate and Developer Evangelist.