Git Exercises

Git Fresher Interview Questions

1. What is Git?

ANS- GIT is a version control system for tracking changes in computer files and is used to help coordinate work among several people on a project while tracking progress over time. In other words, it’s a tool that facilitates source code management in software development.
Git favors both programmers and non-technical users by keeping track of their project files. It enables multiple users to work together and handles large projects efficiently.


2. What do you understand by the term ‘Version Control System’?

ANS- A version control system (VCS) records all the changes made to a file or set of data, so a specific version may be called later if needed.
This helps ensure that all team members are working on the latest version of the file

img
3. What is GitHub?

ANS- To provide Internet hosting for version control and software development, GitHub makes use of Git.


4. Mention some popular Git hosting services.

• GitHub
• SourceForge
• GitLab
• Bitbucket


5.Different types of version control systems.

ANS- Local version control systems have a database that stores all file changes under revision control on disc in a special format.
Centralized version control systems have a single repository, from which each user receives their working copy.
Distributed version control systems contain multiple repositories, and different users can access each one with their working copy.


6. What benefits come with using GIT?

• Data replication and redundancy are both possible.
• It is a service with high availability.
• There can only be one Git directory per repository.
• Excellent network and disc performance are achieved.
• On any project, collaboration is very simple.


7. What’s the difference between Git and GitHub?

Git GitHub
Git is a software GitHub is a service
Git can be installed locally on the system GitHub is hosted on the web
Provides a desktop interface called git GUI Provides a desktop interface called GitHub Desktop.
It does not support user management features Provides built-in user management


8. What is a Git repository?

ANS- Git repository refers to a place where all the Git files are stored. These files can either be stored on the local repository or on the remote repository.


9. How can you initialize a repository in Git?

ANS- If you want to initialize an empty repository to a directory in Git, you need to enter the git init command. After this command, a hidden .git folder will appear.

img

10. How is Git different from Subversion (SVN)?

GIT SVN
Git is a distributed decentralized version control system SVN is a centralized version control system.
Git stores content in the form of metadata. SVN stored data in the form of files.
The master contains the latest stable release. In SVN, the trunk directory has the latest stable release.
The contents of Git are hashed using the SHA-1 hash algorithm. SVN doesn’t support hashed contents.


11. Name a few Git commands with their function.

• Git config - Configure the username and email address.
• Git add - Add one or more files to the staging area.
• Git diff - View the changes made to the file.
• Git init - Initialize an empty Git repository.
• Git commit - Commit changes to head but not to the remote repository.


12. What are the advantages of using Git?

• Faster release cycles
• Easy team collaboration
• Widespread acceptance
• Maintains the integrity of source code
• Pull requests

img

13. What language is used in Git?

ANS- Git is a fast and reliable version control system, and the language that makes this possible is ‘C.’
Using C language reduces the overhead of run times, which are common in high-level languages.


14. What is the correct syntax to add a message to a commit?

ANS- git commit -m "x files created"


15. Which command is used to create an empty Git repository?

ANS- git init - This command helps to create an empty repository while working on a project.


16. What does git pull origin master do?

ANS- The git pull origin master fetches all the changes from the master branch onto the origin and integrates them into the local branch.
git pull = git fetch + git merge origin/ master
After having gone through the beginner level Git interview questions, let us now look at intermediate GIT interview questions and answers.



Intermediate Git Interview Question


17. What does the git push command do?

ANS- The Git push command is used to push the content in a local repository to a remote repository. After a local repository has been modified, a push is executed to share the modifications with remote team members.

img

The `git push` command is used in git version control systems to upload local branch commits to a remote repository. it updates the remote repository with the changes you have made in your local branch.

here's the basic syntax of the `git push` command:
git push <remote> <branch>


- `<remote>` refers to the name of the remote repository where you want to push your changes. it is typically named "origin" by default, representing the remote repository from which you cloned your local repository.
- `<branch>` refers to the branch you want to push to the remote repository. it could be the name of the current branch or any other branch you specify.

when you run `git push`, git performs the following actions:

1. verifies that you have the necessary permissions to push to the remote repository.
2. transfers the commits from your local branch to the remote repository.
3. updates the corresponding branch in the remote repository with your changes.
4. if the remote repository is configured to do so, it may trigger hooks or run additional actions like building and deploying your code.


it's important to note that `git push` only pushes the commits from your local branch that are not already present in the remote repository. if other developers have pushed changes to the remote branch since your last pull or push, you may need to first fetch and merge their changes into your local branch before pushing your changes.

Additionally, you can use various options and flags with the `git push` command to control its behavior, such as specifying the remote branch name, force-pushing changes, or configuring upstream branches. refer to the git documentation for more details on these options.

remember to use `git pull` or `git fetch` to sync your local repository with the remote repository before pushing to avoid conflicts and ensure your changes are up to date.



About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext