Help the world stop coronavirus! Stay home!

Prev Next

Maven / GIT Interview Questions

1. Difference between git commit and git push command. 2. Difference between git pull and fetch. 3. Difference between git stash apply and git stash pop. 4. What is GIT? 5. Main difference between Git and SVN. 6. Advantages of GIT. 7. What is version control? 8. What is a repository in GIT? 9. What is a bare Git repository? 10. What is an Index in GIT? 11. GIT Lifecycle. 12. What language(s) is used in Git? 13. Difference between git fetch and git pull. 14. What do you mean by git add? 15. What is the difference between git init and git init --bare? 16. What does the 'git reset' command do? 17. What is Git stash? 18. Explain git status command. 19. Can we create multiple stashes? 20. Explain git revert command. 21. Difference between git commit and git push. 22. How to view the commit history in git? 23. What is "git commit -a"? 24. Function of git clone command. 25. How do I integrate changes from GIT one branch into another? 26. Difference between git merge vs rebase. 27. Why GIT is considered better than Subversion? 28. Difference between Git and Github. 29. What does git pull origin master do? 30. How do I remove a file from a Git repository without deleting it from the local filesystem? 31. What is HEAD in GIT? 32. What is a detached HEAD in GIT? 33. What is cherry-pick in GIT? 34. What is GIT rebase? 35. What does git shortlog command do? 36. Explain git fsck command. 37. How do I view the file changes (diff) before committing in GIT? 38. Explain git blame command. 39. What is a pull request in git? 40. What is a .GITKEEP file?
Could not find what you were looking for? send us the question and we would be happy to answer your question.

Difference between git commit and git push command.

git commit records changes to the local repository while git push updates the changes to the remote repository and the changes be visible to the other users.

Difference between git pull and fetch.

Git fetch gathers any commits from the target branch that do not exist in your current branch and stores them in your local repository. However, it does not merge them with your current branch.

Git pull update your current HEAD branch with the latest changes from the remote server. This means that pull not only downloads new data and also directly integrates it into your current working copy files.

Difference between git stash apply and git stash pop.

git stash pop removes the stash (topmost) after applying it, whereas git stash apply leaves it in the stash list for possible later reuse.

git stash pop is equivalent to git stash apply and git stash drop.

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.

Git is a free and open source.

Main difference between Git and SVN.

Git is a distributed version control system (DVCS), while SVN is a centralized version control system.

Advantages of GIT.

Distributed Development: In SVN, each developer gets a working copy that points back to a single central repository. Git, however, is a distributed version control system. Instead of a working copy, each developer gets their own local repository, complete with a full history of commits.

Free and open source.

Easier branching.

High availability.

Faciliates team collaboration.

What is version control?

Version control systems are a type of software tools that help software developers manage his changes to source code over time. Version control software keeps track of every modification to the code in a special kind of database. Developers can turn back the clock if necessary and compare earlier versions of the code to help fix the mistake while minimizing disruption to all team members.

What is a repository in GIT?

Git stores project details and files information in a data structure called a repository. The Git repository is stored in the same directory as the project itself, in a subdirectory called .git.

A git repository contains, among other things, the following:

  • A set of commit objects.
  • A set of references to commit objects, called heads.
What is a bare Git repository?

A bare Git repository is a repository that is created without a Working Tree.

git init --bare
What is an Index in GIT?

The index is a single, large, binary file in under .git folder, which lists all files in the current branch, their sha1 checksums, time stamps and the file name.

Before completing the commits, it is formatted and reviewed in an intermediate area known as Index also known as the staging area.

GIT Lifecycle.

What language(s) is used in Git?

The core Git distribution is written in C and (Bourne) shell scripts and also using Perl.

Difference between git fetch and git pull.

git fetch imports commits from a remote repository into your local repo. If you want to reflect these changes in your target branch, git fetch must be followed with a git merge. Since fetched content is represented as a remote branch, it has absolutely no effect on your local development work. This makes fetching a safe way to review commits before integrating them with your local repository. Your target branch will only be updated after merging the target branch and fetched branch.

git pull does a git fetch followed by a git merge. 'git pull' downloads as well as merges the data from a remote repository into your local working files. It may also lead to merge conflicts if your local changes are not yet committed.

git pull = git fetch + git merge
What do you mean by git add?

‘git add .’ command adds all modified and new files in the current directory and all subdirectories to the staging area (index), thus preparing them to be included in the next git commit. Any files matching the patterns in the .got ignore file will be ignored by git add.

What is the difference between git init and git init --bare?

Non-Bare variant creates a repository with a working directory so you can actually work.

The bare git init creates a repository without a working directory.Bare repositories are usually central repositories where everyone moves their work to.

What does the 'git reset' command do?

'Git Reset' resets your index as well as the working directory to the state of your last commit.

What is Git stash?

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

Explain git status command.

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.

Can we create multiple stashes?

Yes. You can run git stash several times to create multiple stashes, and then use git stash list to view them.

Explain git revert command.

The git revert command is used for undoing changes to a repository's commit history. Git revert expects a commit ref passed in. To revert the latest commit use git revert HEAD command.

git revert simply creates a new commit that is the opposite of an existing commit. So a git push need to be followed to update in remote repository.

Difference between git commit and git push.

The git commit records changes to the repository while git push updates remote refs along with associated object.

git commit record your changes to the local repository. git push update the remote repository with your local committed changes.

How to view the commit history in git?

git log command lists the commits made in that repository in reverse chronological so that most recent commits show up first.

What is "git commit -a"?

Git commit with option "a" adds all tracked files to the staging area and commits them in one step. It implicitly runs git add command with -a option and hence we can skip git add.

Function of git clone command.

The git clone command creates a copy of an existing Git repository to the local repository. To get the copy of a central repository, “cloning” is the most common way used by developers.

How do I integrate changes from GIT one branch into another?

In Git, there are two main ways to integrate changes from one branch into another: the merge and the rebase.

Difference between git merge vs rebase.

Both does the same thing (integrate branches) in slightly different way.

The major benefit of rebasing is that you get a much cleaner project history. First, it eliminates the unnecessary merge commits required by git merge.

Why GIT is considered better than Subversion?

GIT is decentralized so your local copy itself acts as a repository to compare and checkin, while remote repository is inaccessible. Subversion is centralized so the repository can get offline and affect work.

Difference between Git and Github.

Git is a revision control system to manage your source code history. GitHub is a hosting service for Git repositories.

What does git pull origin master do?

git pull fetches and as well as merge.

git pull origin master fetches commits from the master branch of the origin remote into the local origin/master branch and then it merges origin/master into the branch you currently have checked out.

How do I remove a file from a Git repository without deleting it from the local filesystem?

To delete a file, use the below command.

git rm --cached app.config.file

to delete a directory, use the below command.

git rm --cached -r directoryToRemove
What is HEAD in GIT?

HEAD is a reference to the last commit in the currently checked-out branch.

What is a detached HEAD in GIT?

Detached HEAD is a state in which a specific commit is checked out instead of a branch.

What is cherry-pick in GIT?

Cherry picking means to choose a specific commit from one branch and apply it onto another.

It is a 2 step process where you need to check-out to the branch where you want to apply the commit and then apply the commit by its commit-hash.

git checkout master

git cherry-pick <commit-hash>
What is GIT rebase?

Rebasing is the process of moving or combining a sequence of commits to a new base commit.

What does git shortlog command do?

The git shortlog command is a special version of git log intended for creating release announcements. It groups each commit by author and displays the first line of each commit message. This is an easy way to see who’s been working on what.

Explain git fsck command.

git fsck ( File System ChecK) is used to validate a file system and finds problems.

git fsck command verifies the connectivity and validity of the objects in the database.

How do I view the file changes (diff) before committing in GIT?

Use the git diff comand as shown below.

git diff "filename_to_diff"

The above command works only when the file is not added already. If it is added already, use the same command with cached option as shown below.

git diff --cached  "filename_to_diff"
Explain git blame command.

git blame command shows what revision and author last modified each line of a file. The command name may be little odd however it is a very useful command that annotates each line in the given file with information from the revision which last modified the line.

What is a pull request in git?

Pull request help project maintainers manage changes from the contributors.

Pull requests let you tell other members of the team about changes you have pushed to a GitHub repository. Once a pull request is sent, interested parties/reviewers can review the set of changes, discuss potential modifications, and even push follow-up commits if necessary.

Once the review is complete and the changes are approved, the changes merged into the main branch from topical/individual branch.

What is a .GITKEEP file?

A GITKEEP file is an empty file that GIT users create so that a Git repository preserves an empty project directory. Otherwise, git cannot preserve the empty directory as it tracks by files. By convention, empty directories that contain no files are not committed to Git repositories. However, a single GITKEEP file in a directory causes Git to preserve the directory in the repository.

«
»
JUnit

Comments & Discussions