Git 101 : An Introduction To Git And How To Use It

Hammad
4 min readMar 6, 2023

--

Photo by Mohammad Rahmani on Unsplash

Introduction

In the world of software development, Git has become an essential tool for developers. Git was created by Linus Torvalds in 2005 for the development of the Linux operating system. In this essay, we will discuss what Git is, how it works, and its advantages. We will also cover how to install Git, create a new repository, clone an existing repository, add files to the staging area, commit changes, push changes to a remote repository, pull changes from a remote repository, and resolve merge conflicts.

I. What is Git and How Does it Work?

A. Definition of Git:

Git is a distributed version control system that allows developers to track changes to their code and collaborate with others on projects. Git is open source, meaning anyone can contribute to its development, and it is widely used in the software development industry.

B. How Git Works:

Photo by Yancy Min on Unsplash

Git works by creating a repository, which is a collection of files that make up a project. Each time a change is made to a file, Git tracks the changes and saves them as a new version of the file. This allows developers to keep track of changes made to their code over time.

Git also allows developers to work on different branches of the code simultaneously. This means that developers can work on different features of a project without affecting the main codebase. Git also allows developers to merge different branches of code together once they have been completed.

C. Advantages of Git:

Git has several advantages for developers. First, Git allows developers to track changes to their code over time, making it easy to identify when a bug was introduced and how it was fixed. Second, Git allows developers to collaborate on projects with others, making it easier to work together on a project. Third, Git allows developers to work on different branches of code simultaneously, making it easier to develop new features without affecting the main codebase.

II. Installing Git

A. Steps to Install Git:

To install Git, follow these steps:

  1. Go to the Git website and download the installer for your operating system.
  2. Run the installer and follow the on-screen instructions.
  3. Once the installation is complete, open the Git Bash terminal to verify the installation.

B. Verifying Git Installation:

To verify that Git has been installed correctly, open the Git Bash terminal and type “git — version”. This will display the

current version of Git installed on your system. If the command returns a version number, Git has been installed successfully.

III. Creating a New Repository

A. Steps to Create a New Repository:

To create a new repository in Github, follow these steps:

Open Git Bash terminal and navigate to the directory where you want to create the repository. Type “git init” to create a new Git repository. This will create a new .git directory in your current directory, which will store all the Git-related files.

B. Adding Files to the Repository:

To add files to the repository, follow these steps:

Create a new file in the repository directory. Type “git add <filename>” to add the file to the staging area. This will add the file to the list of changes that will be committed in the next step.

IV. Committing Changes

Photo by Markus Winkler on Unsplash

A. Steps to Commit Changes:

To commit changes to the repository, follow these steps:

Type “git commit -m ‘<commit message>’” to commit the changes to the repository. This will save the changes to the repository with a commit message that describes the changes made.

V. Pushing Changes to a Remote Repository

A. Steps to Push Changes:

To push changes to a remote repository, follow these steps:

Type “git remote add <remote-name> <remote-url>” to add a remote repository to your local repository. Type “git push <remote-name> <branch-name>” to push the changes to the remote repository.

VI. Pulling Changes from a Remote Repository

A. Steps to Pull Changes:

To pull changes from a remote repository, follow these steps:

Type “git pull <remote-name> <branch-name>” to pull the changes from the remote repository to your local repository.

VII. Resolving Merge Conflicts

A. Steps to Resolve Merge Conflicts:

When merging changes from different branches, conflicts may occur if two branches have made changes to the same code. To resolve merge conflicts, follow these steps:

Type “git merge <branch-name>” to merge the changes from the specified branch. If a merge conflict occurs, Git will highlight the conflicting code and ask you to resolve the conflict manually. Once the conflict is resolved, save the changes and commit them to the repository.

Conclusion

Git is an essential tool for modern software development, allowing developers to track changes to their code, collaborate with others, and work on different branches of code simultaneously. With Git, developers can easily identify and fix bugs, develop new features without affecting the main codebase, and work together seamlessly on projects.As software development continues to evolve, Git will undoubtedly remain a key tool for developers worldwide. So if you haven’t already, consider adding Git to your toolkit and see how it can help you streamline your development process and collaborate more effectively with your team.

If you enjoyed, then you will surely enjoy Open 101 and others also.

Thank you for reading. Wishing you a very happy day

--

--

Hammad

Tech Write | Machine Learning | Blockchain | Philosphy | Technology and Research