Prev Next

DevOps / 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. What language(s) is used in Git? 12. Difference between git fetch and git pull. 13. What do you mean by git add? 14. What is the difference between git init and git init --bare? 15. What does the 'git reset' command do? 16. What is Git stash? 17. Explain git status command. 18. Can we create multiple stashes? 19. Explain git revert command. 20. Difference between git commit and git push. 21. How to view the commit history in git? 22. What is "git commit -a"? 23. Function of git clone command. 24. How do I integrate changes from GIT one branch into another? 25. Difference between git merge vs rebase. 26. Why GIT is considered better than Subversion? 27. Difference between Git and Github. 28. What does git pull origin master do? 29. How do I remove a file from a Git repository without deleting it from the local filesystem? 30. What is HEAD in GIT? 31. What is a detached HEAD in GIT? 32. What is cherry-pick in GIT? 33. What is GIT rebase? 34. What does git shortlog command do? 35. Explain git fsck command. 36. How do I view the file changes (diff) before committing in GIT? 37. Explain git blame command. 38. What is a pull request in git? 39. What is a .GITKEEP file? 40. Which programming language used in GIT? 41. How do I create a new repository in GIT using the command line? 42. What is a .git directory? 43. Mention a few GIT hosting services. 44. What is commit SHA in Git? 45. What is the difference between a GIT tag and a branch?

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.

Read full answer

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

Read full answer

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.

Read full answer

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.

Read full answer

5. Main difference between Git and SVN.

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

Read full answer

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

Read full answer

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

Read full answer

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

Read full answer

9. What is a bare Git repository?

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

Read full answer

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.

Read full answer

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

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

Read full answer

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

Read full answer

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

Read full answer

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

Read full answer

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

Read full answer

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

Read full answer

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

Read full answer

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

Read full answer

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

Read full answer

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

Read full answer

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

Read full answer

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

Read full answer

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

Read full answer

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

Read full answer

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

Read full answer

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

Read full answer

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

Read full answer

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

Read full answer

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

Read full answer

30. What is HEAD in GIT?

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

Read full answer

31. What is a detached HEAD in GIT?

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

Read full answer

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

Read full answer

33. What is GIT rebase?

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

Read full answer

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

Read full answer

35. Explain git fsck command.

git fsck ( F ile S ystem C hec K ) is used to validate a file system and finds problems. git fsck command verifies the connectivity and validity of the objects in the database.

Read full answer

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

Read full answer

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

Read full answer

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

Read full answer

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

Read full answer

40. Which programming language used in GIT?

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

Read full answer

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

Read full answer

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

Read full answer

43. Mention a few GIT hosting services.

Github, Gitlab, BitBucket, SourceForge, Microsoft VSTS, GitEnterprise, and LauchPad.

Read full answer

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

Read full answer

45. What is the difference between a GIT tag and a branch?

In Git, both branches and tags are pointers to specific commits, but they serve different roles in the development lifecycle. Git: Feature, Branch, Tag Comparison Feature Branch Tag Purpose Used for active development (features, bug fixes). Used to mark milestones (releases, version numbers). Mov...

Read full answer

«
»

Comments & Discussions