Home / Interview /Top 50 GIT Intervie...
Admin
2023-09-07
0 mins read
Similar Blogs
How are the data structures and algorithms useful for SDET?
0 mins read
2023-09-14
How To Use DataProvider in TestNG – Parameterization
0 mins read
2023-09-13
What Are The Skills Required for SDET?
0 mins read
2023-09-13
How can I switch from QA to SDET?
0 mins read
2023-09-14
SDET Demand In Market !!
0 mins read
2023-09-13
Essential Skills Required to Become an SDET
0 mins read
2024-05-02
How can a QA or Test engineer become SDET?
0 mins read
2023-09-12
What is the difference between SDET and TESTER?
0 mins read
2023-09-12
What Is TestNG Annotations-Benefits, Hierarchy
0 mins read
2023-09-13
How to write a Good Test Case in Software Testing
0 mins read
2023-09-14
The following set of frequently asked interview questions have been compiled to help students and professionals preparing for Certified SDET professional courses, SDET Foundation Training, Certified SDET Architect courses. You can see the full set of SDET Interview questions here.
GIT is a Distributed Version Control System (DVCS) and Source Code Management System (SCMS) which is used to track changes to a file and also allows reverting back to any particular change. It has the ability to handle small and large projects with efficiency and speed.
The differences between GIT and SVN are as follows:
GITSVNGIT is a Decentralized Version Control tool.SVN is a Centralized Version Control tool. The entire repository can be cloned on the local system. Version history is stored on a server-side Repository. Commits are possible even if offline. Only online commits are allowed. Push/Pull operations are faster. Push/Pull operations are slower. Work is shared automatically on commit. Work is not shared automatically.
The advantages of GIT are as follows:
C is the programming language that is used in GIT.
C ensures that the overhead of runtimes associated with high-level languages is reduced, and hence making GIT faster.
A GIT repository contains a directory named as .git where it keeps all of its metadata for the repository.
All the contents of .git directory are private to GIT.
git commit -a is used to write a commit message in GIT.
The -a is used to instruct the git to commit the new content of all tracked files that have been modified.
If any new file needs to be committed for the first time, “git add<file>” is used before git commit.
Commits can be changed, formatted and reviewed in an intermediate area, before the completion of commits.
This intermediate area is called a Staging Area or Index.
Git Stash takes the current state of the working directory and puts it on the stack for later, and hence providing a clean working directory.
Git Stash is used when we need to switch to any other job and at the same time, we don’t want to lose our existing work.
When we want to remove the stashed item from the list, then git stash drop command is used.
It removes the last added item in stash by default, and it can also remove a specific item if included as an argument.
The git clone command is used to create a copy of an existing GIT repository.
Git clone is the most common way used by programmers to get the copy of a central repository to a local workspace.
git branch –merged master : It shows all branches that are merged into master.
git branch –merged : It shows all branches that are merged into the head.
git branch –no-merged : It shows all branches that are not merged.
The git config command is an easy way to set configuration options for GIT installations.
Git config command is used to define the behavior of a repository, user info, preferences, etc.
For e.g.: We configure global username and email address after installing GIT. However, we can set them now if we missed that step or want to make changes.
git config –global user.name “First_Name” : This will add username.
git config –global user.email “emailAddress” : This will add Email Address.
To create a repository in GIT, create a directory for the project if it does not exist, and then run the command “git init”.
This command will create .git directory in the project directory, the directory does not need to be empty.
Branching is used to create a new own branch till some commits and then can easily switch between those branches. GIT allows having multiple local branches that can be entirely independent of each other.
This will help to go to previous work, keeping the recent work intact.
To delete a local GIT branch, the following command is used:
git branch -d branch_name
To delete a remote GIT branch, the following command is used:
git push <remote_name> –delete <branch_name>
‘git remote add’ just creates an entry into a git config that specifies a name for a particular URL.
While, ‘git clone’ creates a new directory by copying the existing remote repository into a local workspace at the particular URL.
‘git diff’ is used to show the changes between commits, commit and working tree, etc.
The most common scenario to use diff is to see what changes are made after the last commit.
For e.g.:
git diff HEAD [filename] : It compares the working directory with the local repository.
git diff [filename] : It compares the working directory with Index.
git diff –cached [filename] : compare the index with local repository.
‘git checkout’ is a command that is used to update directories or specific files in the working tree with those form another branch without merging it in the whole branch.
The git checkout command operates upon three distinct entities:
Files, commits and branches.
git checkout -b <new-branch>
‘git rm’ command is used to remove individual files or a collection of files.
It is used to remove files from both the staging index and the working directory.
git rm DLA/\*.txt : This will remove all .txt files that are children of DLA directory and any of its subdirectories.
GIT hooks are Shell scripts that are executed before or after the corresponding GIT commands, such as: commit, push and receive.
Git hooks are a built-in feature and there is no need to
download them.
For e.g.: GIT will try to execute a post commit script after a run of the commit.
git command –amend command is used to fix a broken commit in GIT.
This command will fire the commit patch in $Editor. We just need to edit the message right on the top line of the file, save and then quit.
A conflict in GIT arises when the commit that needs to be merged has some change in one file, and also the current commit has changed in the same place in that file.
In this case, GIT is not able to predict which change should take precedence.
A ‘head’ in a GIT is simply a reference to a commit object.
There is a default header referred to as “Master” in every repository. A repository can contain any number of heads.
‘Rebasing’ is an alternative of merging in GIT.
Syntax:
git rebase [new-commit]
‘git add’ is used to add file changes in the working directory to the staging area. It tells GIT that certain updates to a particular file need to be included in the next commit.
git add <file> : Stage all changes in the file for next commit.
git add <directory> : Stage all changes in directory for the next commit.
‘git log’ is used to find specific commits in the project history. It can be searched by date, by author, by message, by file, etc.
For e.g.:
git log –after=“yesterday”
git log –author=”DLA”
‘git reset’ is used to undo all the changes in the local directory as well as in the staging area and resets it to the state of last commit.
Syntax:
git reset
GIT version control is used to track the history of a collection of files, and it also includes the functionality to revert the collection of files to another version.
Each version captures a screenshot of the file system at a certain point of time. All files and their complete history are stored in a repository.
Some of the best GIT client for LINUX are:
Commit object contains the following:
SubGit is a tool that is used for a smooth, stress-free SVN to GIT migration. It is a solution for a company-wide migration from SVN to GIT.
It is widely used for the following reasons:
‘git status’ is used to display the state of the working directory and the staging area.
It allows us to see which changes have been staged, which have not been staged, and which files aren’t being tracked by Git.
Syntax:
git status
‘git stash apply’ command is used to bring back the saved changes onto the working directory.
It is used when we want to continue working where we have left our work.
Syntax:
git stash apply
Git Instaweb automatically directs a web browser and runs web server with an interface into your local repository.
The following command is used to squash the last N commits of the current branch:
git rebase –i
HEAD~{N}
N= no. of commits that you want to squash.
When the above command is run, an editor will open with a list of N commits message, one per line. Each of these lines begins with the word “pick”. Replacing the word “pick” with “squash” or “s” will tell Git to combine the commit with the commit before it. Hence, set every commit in the list to be squashed except the first one to combine all N commits into one.
cherry-pick command is used to copy a commit from one branch to another.
It allows to play back an existing commit to current location or branch.
Simply switch to the target branch and call git cherry-pick {hash of that commit}.
Cherry-pick uses diff to find the differences between branches.
Since merge commit belongs to a different branch, it has two parents and two change sets.
For e.g.:
If we have to merge commit ref 43ad64c, we have to specify -m and use parent 1 as a base:
git checkout release_branch
git cherry-pick -m 1 43ad64c
Git Bisect allows finding a bad commits efficiently.
Instead of checking every single commit to find the one that introduced some particular issue into the code, git bisect allows the user to perform a sort of binary search on the entire history of the repository and hence making it easier to find a bad commit.
This command uses a binary search algorithm to find which commit in the project’s history has introduced an issue. Before the introduction of issue, the commit is referred to as ‘good’ and after the introduction of issue, it is referred to as ‘bad’.
Then this command picks a commit between those endpoints and asks what kind of commit it is. This process continues till it finds the exact commit that introduced the change.
To bring a new feature to the main branch, we can use git merge or git pull commands.
Syntax:
git merge
git pull
Git diff shows the differences between various commits and also between the working directory and staging area.
Git status provides not only the details of the files to be staged in the working repository, but along with provides the status of the comparison with the origin of your branch.
For resolving any conflict in GIT, we need to edit the files for fixing the conflicting changes, and then we need to run ‘git add’ command to add the resolved files.
After that, ‘git commit’ command needs to be run to commit the repaired merge.
A Git fork is simply a copy of a GIT repository.
Forking down a repository in GIT ecosystem enables to freely experiment with different changes with little or no effects on original project.
Various branching strategies are as follows:
•Feature Branching: A feature branch keeps all the changes for a particular feature inside a branch. When the feature is fully tested and validated, then it is merged into master.
•Task Branching: In Task branching, each task is implemented on its own branch with the task key included in the branch name. With this, it is easy to see which code implements which task, just need to find the task key in the branch name.
•Release Branching: We can clone a branch to form a release branch once the develop branch has acquired enough features for a release. Creating the release branch starts the next release cycle, and hence no new feature can be added after this point, only bug fixes are allowed.
GIT is an open-source version control system, it allows running versions of a project, which shows the various changes that were made to the code overtime.
It also allows keeping backtracking if necessary and undo those changes.
In GIT, multiple developers can check out, and upload changes and then each change can be attributed to a specific developer.
Git Is-tree is used to represent a tree object, including the mode and name of each item and also SHA-1 value of the blob or the tree.
‘git push’ command is used to update new local commits on a remote repository.
Syntax:
git push
It is always advisable to create an additional commit rather than amending an existing commit because the amend operation will destroy the state that was previously saved in a commit.
If only the commit message needs to be changed, then it’s not an issue to amend, but if the contents are being amended, then there are more chances of eliminating some important content.
A git pull origin master is used to pull the master branch from the remote repository called origin into your current branch.
This only affects the current branch and not the local master branch
INQUIRY
By tapping continuing, you agree to our Privacy Policy and Terms & Conditions
SkillAhead Solutions
Gurgaon
USA
1603, Capitol Avenue, Suite 413A, 2659, Cheyenne, WY 82001, USA
`Copyright © DevLabs Alliance. All rights Reserved`
|
Refund & Reschedule Policy
Privacy Policy
Terms of Use