Skip to content

The purpose of this repository is to provide job candidates with a resource to prepare for a Git-related interview

Notifications You must be signed in to change notification settings

surbhidighe/Git-interview-questions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

Git-interview-questions

✍️ ----- In Progress ----- ✍️

S.No Questions
1 What is Git
2 What is a repository in git
3 What is the difference between Git and GitHub
4 What is the purpose of git clone command
5 Which command initializes an empty Git repository
6 What is a branch in Git
7 How can we create a new branch in git
8 How to switch branch on git
9 How can you delete a branch both locally and remotely
10 How to list branches in Git
11 How to check if git is installed on your system
12 How can we see most recent commits in git
13 How can we see 5 recent commits in git
14 how to set git user name and email globally
15 How to set git user name and email for a single repository
16 What are the different kinds of branches that can be created in git
17 What is git staging area
18 How to add changes to the staging area

1. What is Git

  • Git is a free and open-source distributed version control system designed to manage source code and other file revisions.
  • Using Git, programmers have the ability to track changes made to their codebase over time, collaborate with other team members, and restore previous versions of their work when needed.

🔝 Scroll to Top

2. What is a repository in git

A git repository is a central location where all the files and directories for a project are stored, along with their complete version history.

🔝 Scroll to Top

3. What is the difference between Git and GitHub

Git - Git is a distributed version control system that allows developers to manage and track changes to their codebase

GitHub - GitHub is a web-based platform that provides hosting for git repositories and also offers a range of collaboration tools.

🔝 Scroll to Top

4. What is the purpose of git clone command

The git clone command enables you to create a local copy of a remote repository.

$ git clone REPO_URL
----------------------
$ git clone https://github.com/surbhidighe/Git-interview-questions.git

🔝 Scroll to Top

5. Which command initializes an empty Git repository

'git init' command is used to initialize an empty git repository

🔝 Scroll to Top

6. What is a branch in Git

  • A branch is a lightweight movable pointer to a commit
  • It provides a way for developers to work on different parts of a project without affecting each other's work
  • It helps to keep the codebase organized and reduces the risk of conflicts between changes made by different people.

🔝 Scroll to Top

7. How can we create a new branch in git

We can use below command to create a new branch -

$ git branch <BRANCH_NAME>

🔝 Scroll to Top

8. How to switch branch on git

If you want to switch to an existing branch, you can use 'git checkout' command and pass the name of the branch you want to switch to.

$ git checkout feature

output - Switched to branch 'feature'

If you want to switch to a non-existing branch, you will need to use the -b option. It will first create a new branch and then switch to that branch.

$ git checkout -b bug-fixes

output - Switched to a new branch 'bug-fixes'

🔝 Scroll to Top

9. How can you delete a branch both locally and remotely

Git won't let you delete the branch you're currently on, so you'll need to switch to another branch before deleting the one you want to delete.

Delete a branch locally

$ git branch -d <BRANCH_NAME>

Delete a branch remotely

$ git push <remote_name> --delete <BRANCH_NAME>

              OR
              
$ git push <remote_name> :<BRANCH_NAME>

🔝 Scroll to Top

10. How to list branches in Git

To list all remote branches

$ git branch -r

To list all local branches

$ git branch

NOTE : the current local branch will be marked with an asterisk

To list all local and remote branches

$ git branch -a

🔝 Scroll to Top

11. How to check if git is installed on your system

The "git --version" command is used to check whether git is installed on the system or not.

🔝 Scroll to Top

12. How can we see most recent commits in git

To see the most recent commits in git, you can use the "git log" command.

🔝 Scroll to Top

13. How can we see 5 recent commits in git

To see 5 most recent commits in git, you can use the "git log -5" command.

🔝 Scroll to Top

14. How to set git user name and email globally

You can set your git username and email globally using the below commands

To set username

$ git config --global user.name "NAME"

To set email

$ git config --global user.email "EMAIL ID"

🔝 Scroll to Top

15. How to set git user name and email for a single repository

You can set your git username and email for a specific repository using the below commands

To set username

$ git config user.name "NAME"

To set email

$ git config user.email "EMAIL ID"

🔝 Scroll to Top

16. What are the different kinds of branches that can be created in git

main - It is the default branch. It contains the latest stable version of the code.

Feature - It is created to develop a new feature or functionality.

Release - It is created to release a new version of your software.

Hotfix - It is used to quickly fix critical bugs or issues that are impacting the production environment.

🔝 Scroll to Top

17. What is git staging area

The staging area is like a container that stores information about the changes you made to your files. It helps you decide which changes to include in your next commit.

🔝 Scroll to Top

18. How to add changes to the staging area

'git add' command is used to add changes to the staging area.

To stage a file named "demo.js"

$ git add demo.js

To stage all files

$ git add .

About

The purpose of this repository is to provide job candidates with a resource to prepare for a Git-related interview

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published