This is the first set of 25 git interview questions and answers also you will know the basics of git.
Git Interview Questions and Answers:
1. What is Git?
Git is free and open source software or distributed version control system for tracking changes in any set of files, usually used for coordinating work among programmers collaboratively developing source code during the software development process.
2. What’s the difference between Git and GitHub?
Simply we can say that Git is a version control system that lets us manage and keep track of our source code history. On the other hand, GitHub is a cloud-based hosting service that lets us manage Git repositories.
3. What is a Git repository?
A Git repository traces and saves the record of all changes made to the files in a Git project.
4. How can you initialize a repository in Git?
To create a new repo, you will use the git init command. git init is a one-time command you use during the initial configuration of a new repo. Executing this command will create a new .git subdirectory in your current working directory. This will also create a new main branch.
# New local repository
git add .
git commit -m “Initial commit”
5. Name a few Git commands with their function.
git add- Moves changes from the working directory to the staging area. This allows for organizing a snapshot before committing it to the official history.
git branch–This command is your general-purpose branch administration tool. It lets create isolated development environments within a single repository.
git checkout–In addition to checking out old commits and old file revisions, git checkout is also the means to navigate existing branches. Combined with the basic Git commands, it’s a way to work on a particular line of development.
git clean– Delete untracked files from the working directory. This is the logical counterpart to git reset, which (typically) only operates on tracked files.
git clone–Creates a copy of an existing Git repository. Cloning is the most common way for developers to get a working copy of a central repository.
git commit–Takes the staged snapshot and commits it to the project history. Combined with git add, this defines the basic workflow for all Git users.
git reset –hard HEAD – command will only revert the top commit means the latest commit.
6. What are the advantages of using Git?
Here are some of the most important advantages of Git:
- It is open-source and free
- It will work on all machines like windows and Linux
- Data redundancy and data replication are feasible
- For one repository we can have only one directory of Git
- The network performance and disk utilization are excellent
- It is simple to collaborate on any project
- We can work on any sort of project within the Git
- It is a highly available service
7. What language is used in Git?
C is the programming language that is used for creating Git which assures that the overheads are receded.
8. What is the correct syntax to add a message to a commit?
On the command line, navigate to the repository that contains the commit you want to amend(edit comment). Type git commit –amend and press Enter.
9. Which command is used to create an empty Git repository?
To create a new repo, you’ll use the git init command. git init is a one-time command you use during the initial setup of a new repo. Executing this command will create a new .git subdirectory in your current working directory. This will also create a new main branch.
10. What are a Remote repository and a Local repository?
Remote repositories are versions of your project that are hosted on the Internet or network somewhere. The main purpose of a remote repository (eg, GitHub) is to publish your code to the world (or to some people) and allow them to read or write it. You can have several of them, each of which generally is either read-only or read/written for you.
Local repositories are physical, locally-managed repositories into which you can deploy your code or file. Using local repositories, Artifactory gives you a central location to store your internal binaries. Through repository replication, you can even share binaries with teams that are located in remote locations.
11. What are push, pull, and fetch in git?
The git push command is used to upload a local repository file to a remote repository. Pushing is how you transfer commits from your local repository to a remote repo.
git fetch is a primary command used to download contents from a remote repository. Fetch is used in simultaneousness with git remote, git branch, git checkout, and git reset to update a local repository to the state of a remote.
The pull command is used to access the changes (commits)from a remote repository to the local repository.
12. What is the difference between a remote branch and a local branch?
The local branch exists on the local machine and can be seen only by the local user. The remote branch is a branch in a remote location. Sometimes, you want to know what files are changed between the local and remote repositories.
git interview questions git interview questions git interview questions git interview questions