GitHub, is a great tool.

GitHub, is a great tool.

learning GitHub part1.

let's learn about the most loved and famous version control system.

GitHub is basically a version control system that keeps track of all your project versions. By version, I mean the change made to your project.

Imagine you are working on an application development that is working fine up to the mark. But then you added another feature that brought bugs in your project or crashed your application. Now you have decided to work on that feature later on but firstly you need to get back your application as it was in its working condition. Here GitHub can help you do that with GitHub you can easily go back to that version where your application was running fine.

So let's get our hands dirty learning this amazing tool.

  • Firstly download Git from here: https://git-scm.com/downloads

    I recommend you to download command line version by clicking on the windows icon.

Once you have downloaded and installed Git on your pc, then start creating a folder where you can store your files and where we can do some git operations. Now open the command line from the folder and start with the very first command which is

git init

The git init command creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new, empty repository. Most other Git commands are not available outside of an initialized repository, so this is usually the first command you'll run in a new project.

Now try running this command :

git status

That should give you something like

git status is a command which lets you know what all changes you have made in the existing files and you can also know whether they are staged or not for commit.

let me explain you about stage and commit here :

Assume that your git has an empty table(stage) and here i am referring to "stage" as a table and "commit" as a photo snap.

Now, whenever you have added any new files or made changes to your existing files those are the files that are not yet staged, meaning they are under your table. To get them on the top of the table all you need is a command that is :

git add .

you can add all unstaged files altogether on the top of the table which is stage using dot ' . ' or you can add them individually by "git add filename".

so now that you have added all your changes, it's time to commit them to your git. Here git commit takes a snap of your files and it considers them as a version.

enough of theory let's just implement and see.

as you can see i have created my first file in the folder and added few texts to it. Now try giving git status.

As I said they are not yet on the table, by this I mean not yet staged in order to stage them we gonna be using the command: git add firstSample.txt(individually) or "git add ." altogether.

so run these commands

  • git add.

  • git commit -m "my first change in the file".

      git commit -m "my first change in the file"
    

Here commit -m "message" or comment is what you are passing while you are committing your changes so that whenever you trace back your commits these comments or messages you passed will make sense for the commit you made.

You can check your commits using the command : "git log".


I have made some changes to the existing file with some random text. After that execute these commands

  • git status (to check the status of unstaged files).

  • git add . (to make them staged).

  • git commit - m "added the second line" (committed it with some message or comment).

Now if you don't want this change and get back to the previous version of your file which is this.

to do that you need to first execute the command: git log and that would give you something like this.

Now copy the hash number of your commit which you want to get back. And execute the command

--git reset hash number

here in the place of the hash number paste your commit hash number which you have copied from the terminal or command prompt.

Once you have executed the reset command you have to proceed with these commands :

  • git add . (getting these changes onto the stage).

  • git stash

stash by using this command your git will place your changes in a special place which you can get whenever you want by this command -- git stash pop

And the same old procedure which is

-- git add .
-- git commit -m "message"

git add . (getting them back on to the stage) and committing them back with a message.

You can also undo the add . command before commit using :

-- git restore --staged filename

we will explore more on GitHub, how to collaborate using that you can also contribute to open source as well, in our next part 2 blog until then keep learning keep growing good bye !!