If you have attended any interview in the recent past, do paste the Git interview questions asked to you in the comments section and weâll answer them ASAP. You can also comment below any questions you have in your mind, which you might face in your interviews.
Answer: 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.
Question: What is a distributed VCS?
Answer: These are the systems that donât rely on a central server to store a project file and all its versions.
In Distributed VCS, every contributor can get a local copy or âcloneâ of the main repository.
Every programmer can maintain a local repository which is actually the copy or clone of the central repository which is present on their hard drive. They can commit and update their local repository without any hassles.
With an operation called âpullâ, they can update their local repositories with new data from the central server and âpushâ operation affects changes to the main repository from their local repository.
Question: What is the difference between Git and GitHub?
Answer: Git is a version control system of distributed nature that is used to track changes in source code during software development. It aids in coordinating work among programmers, but it can be used to track changes in any set of files. The main objectives of Git are speed, data integrity, and support for distributed, non-linear workflows.
GitHub is a Git repository hosting service, plus it adds many of its own features. GitHub provides a Web-based graphical interface. It also provides access control and several collaboration features, basic task management tools for every project.
Question: What is a repository in GIT?
Answer: A repository contains a directory named .git, where git keeps all of its metadata for the repository. The content of the .git directory are private to git.
Answer: The command that is used to write a commit message is âgit commit âaâ. The âa on the command line instructs git to commit the new content of all tracked files that have been modified. You can use âgit add <file>â before git commit âa if new files need to be committed for the first time.
Answer: The difference between GIT and SVN is
- Git is less preferred for handling extremely large files or frequently changing binary files while SVN can handle multiple projects stored in the same repository.
- Git does not support âcommitsâ across multiple branches or tags. Subversion allows the creation of folders at any location in the repository layout.
- Gits are unchangeable, while Subversion allows committers to treat a tag as a branch and to create multiple revisions under a tag root.
Answer: Below are the advantages of using GIT:
- Data redundancy and replication
- High availability
- Only one .git directory per repository
- Superior disk utilization and network performance
- Collaboration friendly
- Any sort of projects can use GIT
- With the Version Control System(VCS), all the team members are allowed to work freely on any file at any time. VCS gives you the flexibility to merge all the changes into a common version.
- All the previous versions and variants are neatly packed up inside the VCS. You can request any version at any time as per your requirement and youâll have a snapshot of the complete project right at hand.
- Whenever you save a new version of your project, your VCS requires you to provide a short description of the changes that you have made. Additionally, you can see what changes are made in the fileâs content. This helps you to know what changes have been made in the project and by whom.
- A distributed VCS like Git allows all the team members to have a complete history of the project so if there is a breakdown in the central server you can use any of your teammateâs local Git repository.
Answer: âGIT PUSHâ updates remote refs along with associated objects.
Answer: GIT is an open source version control system; it will allow you to run âversionsâ of a project, which show the changes that were made to the code overtime also it allows you keep the backtrack if necessary and undo those changes. Multiple developers can checkout, and upload changes and each change can then be attributed to a specific developer.
Answer: Before completing the commits, it can be formatted and reviewed in an intermediate area known as âStaging Areaâ or âIndexâ.
Answer: GIT stash takes the current state of the working directory and index and puts in on the stack for later and gives you back a clean working directory. So in case if you are in the middle of something and need to jump over to the other job, and at the same time you donât want to lose your current edits then you can use GIT stash.
Answer: When you are done with the stashed item or want to remove it from the list, run the git âstash dropâ command. It will remove the last added stash item by default, and it can also remove a specific item if you include as an argument.
Answer:
- git branch --merged master lists branches merged into master
- git branch --merged lists branches merged into HEAD (i.e. tip of current branch)
- git branch --no-merged lists branches that have not been merged
By default this applies to only the local branches. The -a flag will show both local and remote branches, and the -r flag shows only the remote branches.
Answer: The âgit cloneâcommand creates a copy of an existing Git repository. To get the copy of a central repository, âcloningâ is the most common way used by programmers.
Answer: The âgit configâ command is a convenient way to set configuration options for your Git installation. Behavior of a repository, user info, preferences etc. can be defined through this command.
Answer:
- A set of files, representing the state of a project at a given point of time
- Reference to parent commit objects
- An SHAI name, a 40 character string that uniquely identifies the commit object.
Answer: In Git, to create a repository, create a directory for the project if it does not exist, and then run command âgit initâ. By running this command .git directory will be created in the project directory, the directory does not need to be empty.
Answer: A âheadâ is simply a reference to a commit object. In every repository, there is a default head referred as âMasterâ. A repository can contain any number of heads.
Answer: The purpose of branching in GIT is that you can create your own branch and jump between those branches. It will allow you to go to your previous work keeping your recent work intact.
Answer: The common way of creating branch in GIT is to maintain one as âMainâ branch and create another branch to implement new features. This pattern is particularly useful when there are multiple developers working on a single project.
Answer: A âconflictâ arises when the commit that has to be merged has some change in one place, and the current commit also has a change at the same place. Git will not be able to predict which change should take precedence.
To resolve the conflict in git, edit the files to fix the conflicting changes and then add the resolved files by running âgit addâ after that to commit the repaired merge, run âgit commitâ. Git remembers that you are in the middle of a merger, so it sets the parents of the commit correctly.
Answer: Once your development branch is merged into the main branch, you donât need development branch. To delete a branch use, the command âgit branch âd [head]â.
Answer: âRebasingâ is an alternative to merging in git.
Answer: The syntax used for rebase is âgit rebase [new-commitâ.
Answer: âgit remote addâ just creates an entry in your git config that specifies a name for a particular URL. While, âgit cloneâ creates a new git repository by copying and existing one located at the URI.
Answer: With the help of GIT version control, you can track the history of a collection of files and includes the functionality to revert the collection of files to another version. Each version captures a snapshot of the file system at a certain point of time. A collection of files and their complete history are stored in a repository.
Answer: Some of the best GIT client for LINUX is
- Git Cola
- Git-g
- Smart git
- Giggle
- Git GUI
- qGit
Question: What is Subgit? Why to use Subgit?
Answer: âSubgitâ is a tool for a smooth, stress-free SVN to Git migration. Subgit is a solution for a company -wide migration from SVN to Git that is:
- It is much better than git-svn
- No requirement to change the infrastructure that is already placed
- Allows to use all git and all sub-version features
- Provides genuine stress âfree migration experience.
Answer: âgit diff â shows the changes between commits, commit and working tree etc.
Answer: As âGit Statusâ shows you the difference between the working directory and the index, it is helpful in understanding a git more comprehensively.
Answer: âgit diffâ is similar to âgit statusâ, but it shows the differences between various commits and also between the working directory and index.
Answer: A âgit checkoutâ command is used to update directories or specific files in your working tree with those from another branch without merging it in the whole branch.
Answer: To remove the file from the staging area and also off your disk âgit rmâ is used.
Answer: When you want to continue working where you have left your work, âgit stash applyâ command is used to bring back the saved changes onto the working directory.
Answer: To find specific commits in your project history- by author, date, content or history âgit logâ is used.
Answer: âgit addâ adds file changes in your existing directory to your index.
Answer: The function of âGit Resetâ is to reset your index as well as the working directory to the state of your last commit.
Answer: âgit Is-treeâ represents a tree object including the mode and the name of each item and the SHA-1 value of the blob or the tree.
Answer: âGit Instawebâ automatically directs a web browser and runs webserver with an interface into your local repository.
Answer: This directory consists of Shell scripts which are activated after running the corresponding Git commands. For example, git will try to execute the post-commit script after you run a commit.
Answer: Commit message is a feature of git which appears when you commit a change. Git provides you a text editor where you can enter the modifications made in commits.
Answer: To fix any broken commit, you will use the command âgit commitâamendâ. By running this command, you can fix the broken commit message in the editor.
Answer: There are couple of reason
a) The amend operation will destroy the state that was previously saved in a commit. If itâs just the commit message being changed then thatâs not an issue. But if the contents are being amended then chances of eliminating something important remains more.
b) Abusing âgit commit- amendâ can cause a small commit to grow and acquire unrelated changes.
Answer: To co-ordinate with the distributed development and developers team, especially when you are working on a project from multiple computers âBare Repositoryâ is used. A bare repository comprises of a version history of your code.
Answer:
- Pikacode
- Visual Studio Online
- GitHub
- GitEnterprise
- SourceForge.net
No comments:
Post a Comment