Git For Beginners
Git is a version control software that allows you to keep track of changes in a file. So the question that comes to your mind first is, what the hell is version control and why do I need to keep track of changes made in my file. Just sip your coffee and read along.
Why do you need to keep track of your file?
There are situations when writing or programming you would make some changes that would result in errors, then you need a way to revert to the previous state of your file, the next thing that comes to your mind is control z command z right?. But what if you were working on a project with different amount files or you’ve made thousands of changes, I’m 100% sure control z or command z has its limit in which when you close your file, you can’t go back to revert your changes. So you might be interested in a better way to do this, no worries anymore, because I have your solution already, all you have to do is to flick along, I’m pretty sure you are going to find this very much interesting.
What is Version Control?
Version control, as the name implies, is a system that records changes to a file or set of files, so that you can recall specific versions later. There are numerous version control software people use daily, but one of the most popular and interesting is git.
Now that you know what file tracking and version control, now go back to the beginning of this article and digest the git definition there, and make sure you pay yourself with another sip of coffee after digestion. But before I continue, don’t you feel like git has these other functions other than just version controlling or maybe you’ve been ruminating on that. Guess what!! It does, git has more unbelievable functions like coordinating work among different people, and also supports local and remote repository with a service called Github.
Lol, don’t rack your brain yet, I know you are kind wondering what a repository and Github is right?. Repository is just like a blueprint, or a place where your projects are stored while Github is a website that stores git repositories on the internet. Lol, don’t let definitions define your fear. Take another sip of coffee, sit back and read along, and make sure you are following word for word, sentence for sentence, and what else? Oh yeah alphabets for alphabets and numbers for numbers. Okay it’s time we get back to work, Let’s go ahead and install the tools needed for this tutorial.
Tools
Lets go ahead to download and install the softwares below
Git
Git(Mac): https://git-scm.com/download/mac
Git(Windows) : https://git-scm.com/download/win
Git(Linux) : https://git-scm.com/download/linux
Github desktop: https://desktop.github.com/
Did you know after downloading these software, you are already 60% close to being an expert in using git. Okay let’s get over with the gist and move into the real deal.
Before we start, imma give you a brief description of the commands we would be using in this tutorial. Oops, I’m sorry i forgot to tell you this, another interesting thing about git is that we can do everything needed to be done from the terminal, which gives you total control over your computer. Imagine not having to work with a GUI by learning a bunch of steps to do things you can actually do by just writing a line of command. Okay, let me introduce you to the commands, don’t worry, it’s a short one anyways.
-$ git init: This command initializes the git repository locally.
-$ git add <file>: This particular command allows you to add the files that you would want to track.
-$ git commit: i think I’m Xavier in the X-men movie, i read mind a lot, so you are already asking yourself, meeehn, what on earth is commit? Commit is just a way of telling git, take the current snapshot of this repository and save. Commits are always accompanied with a message. Giving the reason why the snapshot is different from other snapshots.
-$ git status: this allows you to check for your current git status. I’m not going to go in depth on this yet, to avoid complicating things.
-$ git push: this allows you to copy your repository from your local server to an online server, which in our case is github.
-$ git pull: when working with other people online, this command allows us to update our local files to the changes made online by those people.
-$ git clone: This command copies a remote or an online repository into your computer.
With these basic commands, we are good to go for a start. Reward yourself with another sip of coffee, take a deep breath and let’s get into the real business.
The first thing we would do is to open up our command prompt
which can be done by using windows + R and type “cmd” into the prompt that pops up. After doing that you should see a black funny window open up, like the one below, that is where all of our commands would go into.
Basically, the next thing we would want to do is to navigate to our preferred working directory in my own case it is documents.
So lets go ahead and change the directory using the cd command like this:
cd Documents
Now, lets go ahead to create a folder for our project using the mkdir command this way:
mkdir GitTutorial
Okay, let’s go ahead and navigate to the folder or directory using the cd command again
cd GitTutorial
Right now, our Command prompt is going to look like this:
Let’s create a file that we would like to track with our git with the Notepad command this way:
Notepad gittutorial.py
This shows you a prompt asking if you want to create a new file with the name, just click yes, now just go ahead and type
What is Lorem Ipsum Lorem Ipsum is simply dummy text of the printing and typesetting industry Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s when an unknown printer took a galley of type and scrambled it to make a type specimen book it has?
and then save.
Get Czar’s stories in your inbox
Join Medium for free to get updates from this writer.
so this our folder is not yet a git folder, so we need a way to kind of invite git into our folder in order for it to be able to track our files for us. So that’s where our git init comes in.
so let’s initialize our folder by using the git init command like this
$ git init
so once we create that, its going to create a .git folder in your directory, this way:
So the .git file contains all the equipment git needs to track our files.
After that is done, we would need to add the file(s) we would like to track, in our case it is only gittutorial.py that is available.
$ git add gittutorial.py
After doing that, nothing happened right? No something actually happened, let’s go ahead and type
$ git status
So what that does is show us the status of our repository, telling us no commits yet and a new file added.
We remove the file, you just type “git rm — cached gittutorial.py”, but we aren’t going to do that right now.
So the next thing we would want to do is to commit our file, meaning we want to save this particular state of our project with a unique message.
Let’s commit, go back to your cmd and type
git commit -m “This is the unique message that differentiates your commit from other commits”
The next part we would look at is how to push to github
So to do that visit https://github.com/
At the top right corner of the screen you would see a add icon, click on it and then new repository.
Its going to show a screen like the one i have below
input your repository name and which in our case is gittutorial and click on create repository.
After creating you would be given a you URL that you can add to your local directory, just go ahead and copy
Then go back to the command line and add the remote link, just like this
$ git remote add “The URL you copied”
Now, lets push to our Remote repository using github. To do that we have to also set as our main/master branch.
so go ahead and type
$ git push set — upstream gittutorial master
go to your github and refresh, you should see a screen like this
Wow, you can now go ahead to gulp all of your coffee because we just “version controled” our file, so you can go ahead to remove and add files, create commits with different messages etc.. Now keep flowing along with your files…
Other Commands:
In upcoming tutorials we are going to be working with the Commands below, so kindly follow me to get updates.
$ git pull
$ git add .
$ git add *.
gitignore
$ git checkout
Feel free to follow me up on
github: https://github.com/Yczar
twitter: https://twitter.com/czarify








