Sunday, May 17, 2020

Crack Interview on git with hands-on exercises Part 1

Objective

The core objective of this article is to share the different ways of asking git related questions in the interviews. I have tried my best to cover basic to experienced level questions. I know covering all git topics are not possible in a single article, therefore, I decided to prepare a series of articles. I’m sure you shall understand git quite easily and it will be helpful for you to crack the git questions.

Please note: I’ve Microsoft Windows operation system in my computer therefore my practical examples will follow the Windows git command pattern.

Best of luck in advance…

What do you know about git? Or

Can you give a brief introduction of git? Or

Have you used git? If yes, what is that?

Explanation:

·        It is Distributed Version Control System

·        It is a Command-Line tool

·        It works in the terminal window and get integrated with PowerShell, Command Prompt terminal

·        Git basically takes an image of what all your files look like at that moment and stores a reference to that snapshot.

·        Though git works in distributed and disconnected mode (until you explicitly push the changes to remote), mostly it works locally.

How can we install git?

Explanation:

a.     Download git from its official site

Download the latest version of git according to the operating server you have in your computer.

https://git-scm.com

git is available for Windows, macOS, and Linux operating systems. The installation is quite straight forward. Just follow the Wizard instructions and do it.

b.     Install through package manager

git can also be installed through chocolatey package manager.

Follow the https://chocolatey.org/packages/git

To install Git, run the following command from the command line or from PowerShell:

 Screen1: Steps of git installation using Chocolatey

How to check the git version using CLI?

Using command prompt or PowerShell, the command is

git version

or

git –version

Both would return the same result.

Do we have git GUI tools for our operating systems?

Indeed, there are a variety of GUI tools are available for Windows, MacOS, and Linux for computer operating systems and few are for Android and iOS mobile operating systems. Though git is a Command-Line (CL) based utility there are various GUI available to use git.

I’ve worked upon the following very popular git GUIs and as per my preference of usage, I have kept these in chronological order.

GUI name

Supported OS

Link to download

Free/Paid

SourceTree

Windows, Mac

https://www.sourcetreeapp.com/

Free

GitKraken

Windows, Mac, Linux

https://www.gitkraken.com/

Free for non-commercial users else paid

GitHub Desktop

Windows, Mac

https://desktop.github.com/

Free

Tower

Windows, Mac

https://www.git-tower.com/windows

Paid

 

How to start working on git?

Before start using git, you must recall that git is a version control system and git has an additional privilege to keep version tracking locally and remotely. So, if you are configuring git, it will manage the repository locally. So, let get started…

I assume, currently, we don’t have anything linked with a remote repository and solely working LOCALLY.

Step 1: Go to your working directory. Initialize the git repository using the following command.

D:\Learning\git>git init LearningProject

This command will initialize the empty git repository in your current working directory.

Once successfully initialized, git will create a hidden directory in your working directory called “.git” and a new folder with your defined project name will be created. In our case it will be “LearningProject”.

Note: It is very very important to understand that the .git hidden folder is the real mechanism that manages all the git related operations on your repository. For a beginner, it is not really necessary to understand the .git folder in detail but for an experienced person, one should at least know some basics.

The .git hidden folder consists of various sub-folders and files. We may have a super quick look.

hooks: Git hooks folder consists of the scripts that are executed before or after the events

info: it contains the exclude file. We’ll discuss .gitignore sometime later.

objects: A much important folder that contains saved content as the hash value.

refs: contains references and tags information

config: This file contains all the configuration you would set for your project is saved permanently in this file like username, email, etc. 

description: this file contains the data about the repositories which can be seen on GitWeb only

HEAD: Head file contains the reference to the branch we are currently working on it.

Step 2:

Put the content in the project folder. Git does not bother what kind of project are you keeping under it.

This could be any type of files or a complete project irrespective of any programming language.

 

Stopping this article here and would come back in Part 2 article with followings:

·        Config git for global usage in your system

·        Create dot net project and apply git commands for version control

Thanks for reading. Happy learning!

 

Abhishek Maitrey

Twitter: @abhimaitrey

This article is also published on :

https://tutorialslink.com/Articles/Git-Interview-Questions-Answers-with-hands-on-exercises-Part-1/1423

 

 

 


No comments:

Post a Comment