Let’s Prepare for the GIT Interview

Şerifhan Işıklı
lTunes Tribe
Published in
7 min readJul 24, 2022

--

In this article, I have compiled the questions that can ask about GIT in the interviews. Other than these, it will be difficult to come across a question and it will be enough to review them before an interview.

What is GIT?

GIT is a distributed version control system and source code management (SCM) system with an emphasis to handle small and large projects with speed and efficiency.

What is the command you can use to write a commit message?

The command that is used to write a commit message is “git commit –a”. The –a on the command line instructs git to commit the new content of all tracked files that have been modified. You can use “git add” before git commit –a if new files need to be committed for the first time.

What is the difference between GIT and SVN?

The difference between GIT and SVN is

Git is less preferred for handling extremely large files or frequently changing binary files while SVN can handle multiple projects stored in the same repository.

GIT does not support ‘commits’ across multiple branches or tags. Subversion allows the creation of folders at any location in the repository layout.

Gits are unchangeable, while Subversion allows committers to treat a tag as a branch and to create multiple revisions under a tag root.

What is a repository in GIT?

A repository contains a directory named. git, where git keeps all of its metadata for the repository. The content of the. git directory is private to git.

How to check if git is available on your system?

$ git --version

How to initialize a new Git repository?

$ git init project
$ cd project

How to tell git about your name and email?

$ git config --global user.name "<your name>"
$ git config --global user.email "<your email>"

How to tell git to not use vi as the default editor?

$ git config --global core.editor "nano -w"

What are the advantages of using GIT?

Data redundancy and replication
High availability
Only one. Its directory per repository
Superior disk utilization and network performance
Collaboration friendly
Any sort of projects can use GIT

What is the function of ‘GIT PUSH’ in GIT?

‘GIT PUSH’ updates remote refs along with associated objects.

How to add a file to the staging area?

$ git add <file>

How to remove a file from the staging area?

$ git reset HEAD -- <file>

How to make a commit?

$ git commit -m "Commit message"

What language is used in GIT?

GIT is fast, and ‘C’ language makes this possible by reducing the overhead of runtimes associated with higher languages.

Why GIT better than Subversion?

GIT is an open-source version control system; it will allow you to run ‘versions’ of a project, which show the changes that were made to the code overtime also it allows you keep the backtrack if necessary and undo those changes. Multiple developers can check out, and upload changes and each change can then be attributed to a specific developer.

Where are git preferences saved?

$ git config --list --show-origin

How to ignore untracked files?

Add them to a local .gitignore file

How to untrack a file without deleting it?

$ git rm --cached <file>

What is “Staging Area” or “Index” in GIT?

Before completing the commits, it can be formatted and reviewed in an intermediate area known as ‘Staging Area’ or ‘Index’.

What is GIT stash?

GIT stash takes the current state of the working directory and index and puts in on the stack for later and gives you back a clean working directory. So, in case if you are in the middle of something and need to jump over to the other job, and at the same time you don’t want to lose your current edits then you can use GIT stash.

What is GIT stash drop?

When you are done with the stashed item or want to remove it from the list, run the git ‘stash drop’ command. It will remove the last added stash item by default, and it can also remove a specific item if you include as an argument.

How can you create a repository in Git?

In Git, to create a repository, create a directory for the project if it does not exist, and then run command “git init”. By running this command. git directory will be created in the project directory, the directory does not need to be empty.

How to undo the most recent commit?

$ git reset HEAD~
$ nano <file>
$ git add <file>
$ git commit -c ORIG_HEAD

How to change the message of the last commit?

$ git commit --amend -m "New message"

How to add a remote repository?

$ git remote add <name> <url>

How to compare a file to the last committed version?

$ git diff HEAD -- <file>

How to rename a remote?

$ git remote rename <old_name> <new_name>

What is the purpose of branching in GIT?

The purpose of branching in GIT is that you can create your own branch and jump between those branches. It will allow you to go to your previous work keeping your recent work intact.

What is the common branching pattern in GIT?

The common way of creating branch in GIT is to maintain one as “Main” branch and create another branch to implement new features. This pattern is particularly useful when there are multiple developers working on a single project.

What is a ‘conflict’ in git?

A ‘conflict’ arises when the commit that has to be merged has some change in one place, and the current commit also has a change at the same place. Git will not be able to predict which change should take precedence.

How can conflict in git resolved?

To resolve the conflict in git, edit the files to fix the conflicting changes and then add the resolved files by running “git add” after that to commit the repaired merge, run “git commit”. Git remembers that you are in the middle of a merger, so it sets the parents of the commit correctly.

How to change the address of a remote?

$ git remote set-url <name> <new_url>

How to send your changes to a remote repository?

$ git push

How to tag a specific commit?

$ git tag -m '...' <commit>

How to get a list of tags?

$ git tag

How to find top contributor?

git shortlog -s -n | head -1

If you remove | head -1 you get all contributors

How to find the first commit?

git log master HEAD~ --oneline | tail -1 | awk '{ print $1 }'

How to create a git alias command?

$ git config --global alias.THEALIASED "WHAT_GIT_COMMAND_TO_ALIAS"

How to use a global .gitignore?

Create ~/.config/git/ignore with a list of patterns.

How to get the list of unpushed commits?

$ git log @{u}..

How to make a commit from another author?

$ git commit --author "Name Surname <email@address>" ...

How to create a branch?

$ git branch BRANCHNAME

How to switch to a branch?

$ git checkout BRANCHNAME

Tip:

$ git checkout -b BRANCHNAME

Will create and switch to the branch called BRANCHNAME

To delete a branch what is the command that is used?

Once your development branch is merged into the main branch, you don’t need development branch. To delete a branch use, the command “git branch –d [head]”

What is another option for merging in git?

“Rebasing” is an alternative to merging in git.

What is the syntax for “Rebasing” in Git?

The syntax used for rebase is “git rebase [new-commit] “

What is GIT version control?

With the help of GIT version control, you can track the history of a collection of files and includes the functionality to revert the collection of files to another version. Each version captures a snapshot of the file system at a certain point of time. A collection of files and their complete history are stored in a repository.

How can you fix a broken commit?

To fix any broken commit, you will use the command “git commit — amend”. By running this command, you can fix the broken commit message in the editor.

What is ‘bare repository’ in GIT?

To co-ordinate with the distributed development and developers’ team, especially when you are working on a project from multiple computers ‘Bare Repository’ is used. A bare repository comprises of a version history of your code.

What is the difference between Git and GitHub?

Git is a revision control system, a tool to manage your source code history.

GitHub is a hosting service for Git repositories.

GitHub is a website where you can upload a copy of your Git repository. It is a Git repository hosting service, which offers all of the distributed revision control and source code management (SCM) functionality of Git as well as adding its own features.

How do you rate GIT in terms of speed?

Git is fast. Speed and performance have been a primary design goal of the Git from the start. With Git, nearly all operations are performed locally, giving it a huge speed advantage on centralized systems that constantly have to communicate with a server somewhere.
Git was built to work on the Linux kernel, meaning that it has had to effectively handle large repositories from day one. Git is written in C, reducing the overhead of runtimes associated with higher-level languages.

What is the difference between git pull and git fetch?

Git pull command pulls new changes or commits from a particular branch from your central repository and updates your target branch in your local repository.

Git fetch is also used for the same purpose but it works in a slightly different way. When you perform a git fetch, it pulls all new commits from the desired branch and stores it in a new branch in your local repository. If you want to reflect these changes in your target branch, git fetch must be followed with a git merge. Your target branch will only be updated after merging the target branch and fetched branch. Just to make it easy for you, remember the equation below:

Git pull = git fetch + git merge

I wish you success in your interviews, do not forget to support

--

--

Şerifhan Işıklı
lTunes Tribe

Senior Software Engineer @Dogus Teknoloji. (Fitness & cycling)