What is Git and why is it used?

Git is a DevOps tool used for source code management. It is a free and open-source version control system used to handle small to very large projects efficiently. Git is used to tracking changes in the source code, enabling multiple developers to work together on non-linear development.


Basic Questions

1. What is a version control system [VCS]?

Version control systems are software tools that help software teams manage changes to source code over time. As development environments have accelerated, version control systems help software teams work faster and smarter.

 

2. What is a git repository?

A repository is a structure of files where git stores all the project-based files. Git can either stores the files on the local or the remote repository.

3. What does git clone do?

Git clone is primarily used to point to an existing repo and make a clone or copy of that repo at in a new directory, at another location. The original repository can be located on the local filesystem or on remote machine accessible supported protocols. The git clone command copies an existing Git repository.

4. What does the command git config do?

The git config command is a convenient way to set configuration options for defining the behavior of the repository, user information and preferences, git installation-based configurations, and many such things. 

For example:
To set up your name and email address before using git commands, we can run the below commands:

git config –global
user.name
“<>”
 

git config –global user.email “<>”

5. Explain head in terms of git ?

The HEAD points out the last commit in the current checkout branch. It is like a pointer to any reference. The HEAD can be understood as the “current branch.” When you switch branches with ‘checkout,’ the HEAD is transferred to the new branch.

6. What is a conflict?

A merge conflict is an event that takes place when Git is unable to automatically resolve differences in code between two commits. Git can merge the changes automatically only if the commits are on different lines or branches.

7. What is the use of command git ls-tree ?

List the contents of a tree object.
 

git ls-tree [-d] [-r] [-t] [-l] [-z]
[–name-only] [–name-status] [–object-only] [–full-name] [–full-tree] [–abbrev[=]] [–format=]
[…]

 

8. Git Status Command do ?

The git status command displays the state of the working directory and the staging area. It lets you see which changes have been staged, which haven’t, and which files aren’t being tracked by Git. 

9. What is Git add command do ?

The git add command is used to add file contents to the Index[Staging Area] .This command updates the current content of the working tree to the staging area. It also prepares the staged content for the next commit. Every time we add or update any file in our project, it is required to forward updates to the staging area.



Intermediate GIT Interview Questions
 

1. What is git stash?

git stash temporarily shelves [or stashes] changes you’ve made to your working copy so you can work on something else, and then come back and re-apply them later on.

2. command used to delete a branch?

The command to delete a local git branch can take one of two forms:

  • git branch –delete old-branch
  • git branch -d old-branch

3. differentiates between the commands git remote and git clone?

They are two completely different things. git remote is used to refer to a remote repository or your central repository. git clone is used to copy or clone a different repository.

4. What is git pull and git fetch ?

git fetch is the command that tells your local git to retrieve the latest meta-data info from the original [yet doesn’t do any file transferring. It’s more like just checking to see if there are any changes available]. git pull on the other hand does that AND brings [copy] those changes from the remote repository.

5. differences between “pull request” and “branch”?

A branch is just a separate version of the code. A pull request is when someone take the repo, makes their own branch, does some changes, then tries to merge that branch in [put their changes in the other person’s code repository]. [In the most general of terms.]

``

6. Difference between Git and GitHub?

While Git is a tool that’s used to manage multiple versions of source code edits that are then transferred to files in a Git repository, GitHub serves as a location for uploading copies of a Git repository.

7. Git diff and git status commands do?

The main difference between the commands is that git diff is specially aimed at comparisons, and it’s very powerful at that: It can compare commits, branches, a single file across revisions or branches, etc. On the other hand, git status is specifically for the status of the working tree.

Leave a Reply

Your email address will not be published. Required fields are marked *