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? 41. Which programming language used in GIT? 42. How do I create a new repository in GIT using the command line? 43. What is a .git directory? 44. Mention a few GIT hosting services. 45. What is commit SHA in Git?
Could not find what you were looking for? send us the question and we would be happy to answer your question.

1. 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.

2. 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.

3. 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.

4. 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.

5. Main difference between Git and SVN.

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

6. 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.

7. 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.

8. 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.
9. What is a bare Git repository?

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

git init --bare
10. 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.

11. GIT Lifecycle.

12. What language(s) is used in Git?

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

13. 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
14. 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.

15. 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.

16. 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.

17. 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.

18. 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.

19. 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.

20. 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.

21. 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.

22. 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.

23. 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.

24. 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.

25. 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.

26. 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.

27. 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.

28. 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.

29. 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.

30. 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
31. What is HEAD in GIT?

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

32. What is a detached HEAD in GIT?

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

33. 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>
34. What is GIT rebase?

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

35. 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.

36. 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.

37. 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"
38. 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.

39. 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.

40. 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.

41. Which programming language used in GIT?

Git is developed using the "C" programming language. C language makes Git fast by evading runtime overheads.

42. How do I create a new repository in GIT using the command line?

To create a repository, you need to create a directory for the project if it does not already exist, and then simply execute the command git init. By executing this command, a .git directory will be created inside the project directory, meaning that now your project directory has turned into a Git repository.

43. What is a .git directory?

The .git directory contains all the metadata of the repository and maintains a track of all the changes made to the files in your repository, by keeping a commit history.

All the details regarding commits, hooks, refs, object databases, remote repository addresses, etc. reside in this folder. This folder plays a crucial part of Git. When you clone any Git repository on your local machine, this .git is the directory that actually gets copied.

44. Mention a few GIT hosting services.
  • Github,
  • Gitlab,
  • BitBucket,
  • SourceForge,
  • Microsoft VSTS,
  • GitEnterprise,
  • and LauchPad.
45. What is commit SHA in Git?

"commit hash" is a unique identifier generated by Git, allows you to keep a record of what changes were made when and by who.

«
»
DEVOPS Interview questions

Comments & Discussions