Beginner’s Guide to Git: The Ultimate Version Control System

August 9, 2022 | Comments(0) |

TABLE OF CONTENT

1. Introduction to Git
2. Git Installation on Windows
5. Git Installation on Max OS X
6. Git Installation on Linux
7. Undo the last Commit
8. Takeaway
9. About CloudThat
10. FAQs

 

Introduction to Git

In the era of distributed development, when developers are involved in multiple projects, they can clone every project’s Git repository and work on it without worrying about versioning. Git is a version control system for tracking changes in a project directory. It is a free and open-source distributed version control system that handles everything from small to massive projects quickly and efficiently. It was initially developed in 2005 by Linus Torvalds.

A large number of commercial projects, as well as open-source projects, rely on Git for version control.

Git Installation on Windows

Git for Windows stand-alone installer:

  1. Download the latest Git for Windows installer.
  2. Once the installation starts, the Git Setup wizard appears on the screen.
  3. Follow the prompts and complete the installation.
  4. Now, go to the command prompt and set up a username and email with the following commands:

git config –global user.name “Sonam”

git config –global user.email sonamk@xyz.com 

These details will be part of any commits that you make.

Git Installation on Mac OS X

Open a terminal and check if Git is already installed.

If you want to install the newer version, the easiest way is by the stand-alone installer.

  1. Download the latest Git for Mac installer.
  2. Follow the steps to install Git.
  3. Now, open the terminal and check if the installation was successful by typing:
  4. Set up your username and email using the following commands:     git config –global user.name “Sonam”    git config –global user.email sonamk@xyz.com 

These details will be part of any commits that you make.

Git Installation on Linux

  1. Go to a shell and add the below command:
  2. Now check if Git has been installed:
  3. Now, set up a username and email with the following commands:

These details will be part of any commits that you make.

Once you have Git installed, you can create a local git repository.

Go to the command prompt or your terminal and follow the commands.

Git

You have your mygit folder created on the desktop.

To initialize a git repository in the folder’s root, run the Git init command.

Git

Create a new file in mygit folder.

Git

Git

Git does not track your file until you tell it to do.

To check which files are being tracked by Git, use the git status command.

Git

Now, you need to tell Git that you want it to track the file that you created.

Use the Git add filename command.

Git

It is time to create a commit.

Use git commit -m “Message “command for commit.

Git

You have successfully done your first commit.

Undo the last Commit:

git

Use the revert command to undo changes and revert to the previous commit.

To undo a published commit

A hash is a code that identifies each commit. Obtain a hash by running:

git

You can also specify multiple users in .gitconfig:

You can configure an individual repo to use a specific user/email address which overrides the global configuration.

From the root of the repo, run

The default user/email is configured in your  ~/.gitconfig

There are other commands which you can explore while working on Git like:

Shows which branch you are currently in.

Git

To create a new branch.

git

  • git pull

The git pull command first performs ‘git fetch’, downloading the content from the specified remote repository and then updating the local repo to match the content.

  • git push

Assume we’ve made some modifications to the file and want to push them to a certain branch of our remote repository. The files in the local repository can be synchronized with the remote repository on Github.

  • git branch -d [branch name]

This command is used to delete a local git branch

  • git push [remote_project] –delete [branch_name]

This command is used to delete a remote git branch

  • git log

This command is used when we want to examine the commit log for each commit in our repository in detail.

  • git stash

When we wish to save our work without staging or committing it to our Git repository and swap between branches, we can use this command.

  • git merge

This command will merge numerous commit sequences into a single history. Git merge is used to merge two branches in the most common usage situations.

  • git fetch

When we execute the Git fetch command, Git gets any commits from the target branch that isn’t in our current branch and places them in our local repository. It does not, however, combine it with our current branch.

Takeaway

I hope this post has explained the fundamentals of Git. Git is easy to learn and has outstanding performance. With the integrity of managed source code as a top priority in design, Git maintains good security. Git uses a cryptographically secure hashing algorithm which is known as SHA1.

It helps to protect the code and the change history against accidental and malicious change. It also makes sure that the history is fully traceable. Feel free to experiment with them to ensure you understand how they work.

About CloudThat

CloudThat is the official AWS (Amazon Web Services) Advanced Consulting Partner, Microsoft Gold Partner, Google Cloud Partner, and Training Partner helping people develop knowledge of the cloud and help their businesses aim for higher goals using best-in-industry cloud computing practices and expertise. We are on a mission to build a robust cloud computing ecosystem by disseminating knowledge on technological intricacies within the cloud space. Explore ouconsulting here.

If you have any queries regarding Git, GitHub, or other version control systems, drop a line in the comments section. I will get back to you at the earliest.

FAQs

  1. What is the difference between Git and Github?

Git is a distributed version control system that monitors source code changes while developing software. It facilitates collaboration among programmers but may also be used to monitor changes to any collection of files. Speed, data integrity, and support for distributed, non-linear operations are Git’s three key goals.

  1. Which language does Git use?

Git is written in C. GIT is quick, and the “C” language enables this by minimizing the runtime overhead associated with high-level languages.

  1. What is a repository in Git?

The place where Git saves all the files is called a repository. Git can use both the local and remote repositories to store files.


Leave a Reply