AWS, Cloud Computing

5 Mins Read

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

Voiced by Amazon Polly

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.

Customized Cloud Solutions to Drive your Business Success

  • Cloud Migration
  • Devops
  • AIML & IoT
Know More

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.

git –version

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:

git –version

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:

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.

Fig1

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 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.

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

Use the Git add filename command.

fig6

It is time to create a commit.

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

fig7

You have successfully done your first commit.

 

Undo the last Commit:

fig8

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

To undo a published commit

git revert [hash]

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

git log

fig9

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

git config user.name “Your name here” git config user.email “Your email here”

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

git config –global user.name “Your name here” git config –global user.email “Your email here”

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

git branch

Shows which branch you are currently in.

fig10

  • 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 also the official AWS (Amazon Web Services) Advanced Consulting Partner and Training partner and Microsoft gold 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. Our blogs, webinars, case studies, and white papers enable all the stakeholders in the cloud computing sphere.

Drop a query if you have any questions regarding Git, GitHub, or other version control systems and we will get back to you quickly.

To get started, go through our Consultancy page and Managed Services Package that is CloudThat’s offerings.

Get your new hires billable within 1-60 days. Experience our Capability Development Framework today.

  • Cloud Training
  • Customized Training
  • Experiential Learning
Read More

FAQs

1. What is the difference between Git and Github?

ANS: – 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.

2. Which language does Git use?

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

3. What is a repository in Git?

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

WRITTEN BY Sonam Kumari

Share

Comments

    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!