Git from Scratch – ScrewLinux ( Part 1 )

Git from scratch

Let’s learn Git from scratch. Some of you guys think that git is very difficult to learn. But if you can get the git concepts to your brain correctly, it is very easy. Yes, Git has some sort of commands, But the main point is not the commands, the concept. This lesson has some new commands for us. So we will discuss everything very simply to catcup the basics of Git.

What is Git ?

Git is a popular distributed version control system. It is free and open source. We use this to track the changes over time in our files, our projects, our codes and any set of files.

Benefits of using a version control system

The version control software saves all the changes you have done in a repository. Guess if you have done any mistakes, you can undo the change. Also you can compare the current versions with the older versions to resolve any issues. Additionaly Git can be integrated with automation tools.

What are some other version control systems available ?

  1. Apache Subversion (SVN)
  2. Mercurial

What Git changes from SVN ?

Git is installed in a seperate workstation and Each developer or any user can have a complete copy of the full version history of the project on their local machines. The users can do their changes localy and don’t need to connect to the main server every time. But in SVN the developer/User downloads only the copy which he is working on to his local machine. So evevry time the user must be online and have to connected to the main server to commit the changes back to the server.

So while Git becomes a distributed version contol system, svn is a centralized system. SVN is a centralized because all the files, history saves under a single location.

In Git, All the users have same permissions for files while in SVN users can be given different permissions on directory/path/file level.

Since SVN uses a single server for file storing, there is a single point of failure. If the server is unresponsive, any lost in network, a server down can be a distruption for the whole project since all the project files are saved only in one location. But in Git, all the users/developers are able to get the complete copy of the project from the workstation in to their local machine. So in a situation like lossing any file from the main server, can be resolved since any user can push their copy to the main workstation. In SVN. the users are having copies of files only they are working.

What is a Git repository ?

There is a hidden direcotory inside of your working direcory. So this hidden direcory is “.git/”. This is the git repository. You will see this directory at the middle of this article series. This repo tracks all the changes done to your files over time.

Let’s begin to learn the fundamentals of Git

Git Basic Workflow

There are few areas we should learn

  1. working tree
  2. Staging area
  3. Local Repository
  4. Remote Repository

working tree ( working area ) is your working folder which contains your .git repo directory and other sub directories. Simply this is where you are currently working. All the files you are working is placed in this directory and also this area is known as untracked area. Any files you have changed in this area must be added to the staging area, if not any change you made will be deleted. Because git don’t understand working tree and it needs to be asked to git to pay attention to the new files in the working directory.

staging area is the area where git can understand and track the file changes. Also it saves the file changes to be added to the git repository on anytime you commit the changes. The changes added to the staging area reflects the files in local repo. When we tell git that i want to track the new files or the new modifications, then git add those files from your working tree to the staging area.

Local repository is all the files inside of .git directory. All the config files, Branches, Heads, Commits ( Snapshots ) are saved in this local repository. So please don’t delete this directory. git commit command will take all the tracked files in staging area and put all together to the local repository.

Remote repository is your master repo which is located in remotely. Guess Github is your remote repository.

This article, “Learn Git from scratch” covers only the fundamentals and the concepts in Git. We will discuss the Git commands in the next article. Also there are some more concepts need to be discussed, they will be more usefull when we discuss while we are using the commands.

Leave a Reply