Learn Git & Github

Learn Git : Lesson 1

Why Git or any VCS

git logo
Image from git-scm

Version control system is a software which maintains the records of changes done to a project and also the states of the project which you can switch anytime. As a programmer, it sometimes happens to me when i write a piece of code and it works but when i try to optimize it then it gets broken. Also i could not be able to traceback the changes and get my working code back. If this happens to you also then you might undo tens of times to get back the previous code.

But what will you do if your project contains multiple files with hundred lines of code in each file. If you now brong some changes to more than one file then its not easily possible to get back the working code. Here comes the importance of a version control system. In a VCS, you can save the current state and continue to work on a different state but it doesn't mean that vcs creates a copy of the current state. No. It maintains the record of the changes bring to a project. It maintains a history which you can navigate to get what state you want.

About this guide

Git has becoming very popular nowadays as the open source softwares are emerging in the market so a lot of developers want to know what exactly git is. Not only knowing about the git, learning and understanding it is also needed to develop large softwares/products with a team. There are many tutorials, guides, video lectures are available to learn git then why this one more guide ? The reason i am writing this guide is that after learning git from various guides, we'll still be wandering stackoverflow to get help for our unique scenarios. So what's wrong with other guides ?
All other guides lack one common thing, User perspective. Many of the guides are written to provide the theoretical knowledge of git commands but don't tell the other uses of the same command. In this guide, i'll not only cover the git basic commands, but will also tell you various tips and tricks to get your task done in git. You won't just get to know about git commands but will understand what these commands do and can do. Not only the commands, how git works is also important to understand.
So this guide will make you fall in love with git. Its not that other VCS are not good but i know about only git and other VCS also work in the same way but the syntax gets different. Below is the list of topics, i'll be covering.


Topics
  1. How Git works
  2. Get yourself on Github
  3. Using commands the smart way

How git works

Git and many vcs have such terms in their terminology like branches, commits, head, master etc. We'll use these terms and will see how actually git works.

  1. Branch :A branch is a state of the project on which you are working. For example, suppose you create a project and name it P1.0. Now you want to modify some code without breaking the working code then what you do is you create a branch and name is what you want. Now whatever changes you bring to that branch does not effect the branch P1.0. In this way you can safely work on your differnt branches without breaking anything.
  2. Commit :Saving a change is called commit. If you change something in your branch then you should commit/save it so that it gets recorded it git history. An important advice:- Commits should be small changes. If you have changed a lot in your project and you commit it. Then you find out that it has broken the code then you'll have to write the whole changes again to fix it. Instead of doing large commits, you should change small, commit it, then change small, commit it and so on. This way you can navigate git history to get to the commit where the code seems to broken. 10 smaller commits are much much better than 1 large commit.
  3. Head :Git maintains a pointer called HEAD to the current working branch and commit. When you navigate the git history then what you do is you actually change this HEAD pointer to that branch or that commit. So HEAD is just a pointer.

Git Tree

Now lets have a look at the git tree.

Git Tree

In this tree, you can see that the nodes of this tree are commits which you do in a branch. There you can see 3 branches. In this tree i have a growing branch which has stable versions of my project which are 1.0, 1.2 and 1.6. Then there are 2 branches for testing phase of my versions which are 1.0-test and 1.2-test. The main thing about git is that you can jump between branches and commits whenever you want. In the 3rd lesson, i will tell you how to navigate git history. So stay tuned.


Comments

Popular posts from this blog

Search box for blog or website

Image Search Engine Using Python

Cordova viewport problem solved