Git : A basic understanding for every DEV - Part I

Git : A basic understanding for every DEV - Part I

·

3 min read

Git is a Distributed Version Control System and it is a kind of content tracker, it stores all our code changes. Distributed means it has a remote repository which is stored in a server and a local repository which is stored on the computer of every developer working on a project. Every developer has a full copy of the code base. We can go back in time, without losing any new changes. We have access to the entire project history.

  • We can think of version control from the perspectives of content, teams, and agility.

  • Version control manages a collection of changing and improving files which we can call a project. The complete history of the project is tracked and available at any time.

  • Version control also supports teams working on that collection of files.

  • Teams work in many different ways, and a good version control system will support many of their workflows or ways of getting work done.

  • Version control helps support collaboration on the project and improves quality by facilitating team communication and reviews.

  • Finally, version control enables agility, the ability to adapt quickly and constructively to a changing environment.

What type of content can be managed with version control?

  • Most version control systems don't really care. Any content that you value and want to continuously improve is a good candidate for version control.

  • Git is commonly used for managing source code related to software projects.

  • Git is especially good at managing text-based content like this. Code that is used to run tests is also a good candidate for version control. The tests need to be properly managed and are usually always improving.

Types of Repositories

  • Git has two repository types

  • Local Repository

  • Local Repository is on your own machine, so you have direct access to it.

  • Remote Repository

    • Remote Repository is usually a centralized server.

Now we will take a look at initializing a git repository

Let's initialize a local git repository

  • Go into a project folder and initialize git

      $ mkdir newdemofolder
      $ cd newdemofolder/
      $ git init
    

    We have initialized an empty git repository in a .git folder

    To list all the contents of the folder including the hidden folder such as the .git folder.

      $ ls -a
    

    Let's add a file to a project

    • Create a file with a basic sentence

        $ touch demofile1.txt
        $ echo "This is a text in demofile1" >> demofile1.txt
      
    • To see the status of the git

        $ git status
      

git status

  • The default branch will be the master branch

  • Untracked files are files that are not added to the git

git add

  • To add a file to the staging area

    $ git add demofile1.txt
    

git commit

  • To commit the changes

    $ git commit -m "Added first commit"
    

git Log

  • To know about other commits information such as commit hash, the author name and the date
 $ git log
  • To easily show commit details as one line
 $ git log --oneline

A Git repository contains a series of snapshots of the project over time which are known as commits. Each commit contains all of the directories and files of the project at the time the snapshot was taken.

You can go back and view the project at earlier points by viewing the older commits.

Want to learn and explore more about git? Then do checkout the next blog Git: A basic understanding for every DEV - Part II

Hop into the blog section for a more interesting and detailed overview of Software development and other stuff. 😊

Did you find this article valuable?

Support Rohit Sah by becoming a sponsor. Any amount is appreciated!