Top 50 Git Interview Questions and Answers | Git Interview Preparation | DevOps Training | Edureka

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello guys this is Arvind here from indica and I welcome you all to this session on gift interview questions so before we move any further let us have a quick look at the agenda for today's session we will start this session by the beginners level of interview questions then we will proceed to the intermediate level questions and finally we will conclude with the advanced level of interview questions asked or gate I hope I'm clear with the agenda guys pretty simple and just a reminder in case you have not yet subscribed to our YouTube channel please do subscribe and also click on the bell icon so that you never miss an update from Eddie Rekha so without any further delay let us begin with our first topic that is the basic level of or the beginner level of interview questions so the first question is what is key it is a distributed version control system it lets you track changes make profile and allows you to revert back to any particular change that you wish to it is a distributed architecture that provides many advantages over other version control systems like the SVN one of the major advantage is that it does not rely on a central server to store all the versions of a projects files so what happens in goodness instead every developer clones a copy of a repository as you can see in this diagram and he has the full history of the project available on his hard drive so whenever there is a server outage all you need to do is just copy one of your teammates locally get repository and bang you have the code on your system so there is one central cloud repository where the developers can commit changes and share them with the other team members so this is what it is in a nutshell so the next question is what is a distributed version control system so these are the systems that don't rely on a central server to store a project file and all its versions you can see the diagram that is on your slide right now in a distributed version control system every contributor can get a local copy or a clone of the main repository here every programmer can maintain a local repository which is actually the copy or the clone of the central repository which is on their hard drive so developers can commit and update the local repository without any hassles with an operation called pull they can update their local repositories with the new data from the central server and pull operation effects changes to the main repository from their local repository the next question is what are the advantages of using a version control system so with version control system all the team members are allowed to work freely on any file at any given time version control system 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 version control system or 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 your hand so whenever you save a new version of a 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 files content this helps you know what changes have been made in the project and by whom finally a distributed version control system leggett allows the team members to have a complete history of the project so that if there is a breakdown in the central server you can use any of your teammates local git repository so these were a few advantages of using the version control system the next question is what is the difference between gate and SVN so git is a decentralized version control tool whereas SVN is all centralized version control boom gate belongs to the third generation of the version control tools whereas SVN belongs to the second generation of the version control tools so what happens in gate is clanks can clone entire repositories on their local systems whereas in SVN version history is stored on this server side of the repository in gate commits are possible even if you're offline whereas in SVN only online commits are allowed so indeed the push and pull operations are comparatively faster whereas in Esfahan the push-pull operations are comparatively slower git works are shared automatically by commit command whereas in SVN nothing is shared automatically so these were a few differences that you can mention in question okay so the next question is what is the difference between gate and github so as we have already seen git is a version control system of distributed nature that is used to track changes in the source code during software development so get aids in coordinating work among programmers but it can be used to track changes in any set of files so the main objectives of get our speed data integrity support for distributed non-linear workflows whereas github is a git repository hosting service plus it adds many of its own features so gator provides a web-based graphical interface it also provides access control and several collaboration features basic task management tools for every project so the next question is what language is used in git so here instead of just telling the name of the language you should also mention the reason for using this language as well so git uses C language git is fast and C language makes this possible by reducing the overhead of runtimes associated with high level languages the next question is mentioned the various git repository hosting functions the following are the main get repository hosting functions as you can see on the slide github get lab with buckets SourceForge and get enterprise and as per my opinion the github is the most popular among these options so the next question is what is a repository ended so repository ingot is a place where git stores all the files so git can store all the files either on the local repository or on the remote repository the next question is what is a bear repository in git so a barely positive in gate contains information about the version control and no working files and it doesn't contain this special dot gifts subdirectory instead it contains all the contents of the dot git subdirectory directly in the main directory itself whereas the working directory consists of two things the first one is a dot git subdirectory with all get related revision history of your repository and the second one is a working tree or checked out copies of all your project files the next question is what is a commit message so a commit message is nothing but an information that you provide along with the command called commit so that you are aware of what exactly that change the developer or the programmer is doing while committing any operation or any change so as you can see here the syntax for commit messages get committed the option and the message that you want to write so the next question is explain some basic gate commands so as you can see here on the slide these are the various commands some basic eight commands that you should be aware of so the first command is the git init command as we have already seen what is the repository in it so this command is used to create a new local repository the next command is the git status command so this command lists the files that you have changed and those you need to add or commit the next command is get clone so this command creates a working copy of a local repository and the syntax is get clone and the URL the next command is the git add a command so this command adds one or more files to this staging area of git so what exactly is staging area we will see in the subsequent part of this session the next command is get commit command as we have seen previously what commit messages that time we discussed just one thing about the commit command so this command commits any files you have added with guitar and also commits any files you have changed since then and the same tax is pretty much simple get commit and the option the next command is git push origin master so this command sends changes to the master branch of your remote repository so these are the some basic commands that you can explain so the next question is how do you fix a broken commit so in order to fix any broken commit you can use the command git commit - - amend so when you run this command you can fix the broken commit message in the editor so the next question is what is a conflict in game so git can handle on its own most merges by using its automatic merging features there arises a conflict when two separate branches have made edits to the same line in a file or where a file has been deleted in one branch but it has been edited in the other branch so conflicts are most likely to happen when working in a team environment the next question is how do you resolve a conflict in gate so you can refer the diagram for more information about this question so there are a few steps that you need to follow to resolve a conflict and get the first step is identify the files that have caused the conflict in the second step you make the necessary changes in the files so that the conflict does not arise again in the third step you add this files by using the command get add and finally to commit the changed file use the command git commit so these were the four steps that you need to follow to resolve a conflict and K the next question is how do you revert a commit that has already been pushed and made public so there can be two approaches to tackle this question and you must include both the approaches in your answer because any one of them can be used depending upon the situation so the first approach is remove or fix the bad file in a new commit and then push it to the remote repository this is the most obvious way to fix an error once you have made the necessary changes to the file then commit it to the remote repository using the command git commit - M and the commit message in the second approach you can create a new commit that undoes all the changes that were made in the parent commit to do this you need to each use one command called git River so we will talk about get revert in the subsequent part of this session syntax for get revert is very simple so get a revert and the name of the commit or the commit ID the next question is what is sub get so sub get is a tool for SEO and public migration it can create a writable get mirror of a local or a remote subversion repository and use both subversion and git as long as you like now you can also improve some of the advantages like you can do a fast one-time import from subversion to get or use sub get with Atlassian bitbucket server we can use sub get to create a bidirectional get SVN mirror of an existing subversion repository you can push to get or commit to subversion as per your convenience synchronization will be done by so the next question is what is the difference between get pull and get fetch get pull command pulls new changes or commits from a particular branch from your central repository and updates your target branch in your local repository whereas git fetch is used for the same purpose but it works in a slightly different way when you perform a gift fetch it pulls all new commits from the desired branch and stores it in a new branch in your local repository if you want to reflect this changes in your target branch git fetch must be followed with a git merge so in this case your target branch will only be updated after merging the target branched and the fetched branch so just to make it very simple for you this one equation that you must remember so get pull equal to get fetch plus git merge so what is the staging area or the index in get before completing the commits any change can be formatted and reviewed in an intermediate area known as the staging area of the index so you can refer the diagram on your slide for more reference so this will give you a clear-cut idea of what exactly is the staging area the next question is what is the use of gate insta web kit in Slovak is used to automatically direct of web browser and run a web server with an interface into your local repository so now we will have a look at the intermediate level of interview questions so the next question is what is gate is trick so gate is Trey represents a tree object including the mode and the name of the each item and the sha-1 value of the block or the tree the next question is what is good stash so in this question you should first explain the need for get stash so often when you have been working on part of your project things are in a message state and you want to switch branches for some time to do something else so the problem here is you don't want to do a commit of half-done work just so that you can get back to this point later so to solve this issue there is one provision called gets - so stashing takes your working directory that is your modified track files and stage changes and saves it on a stack of unfinished changes that you can reapply at any time next question is what is the function of get stash apply so as we have seen previously if you want to continue working where you had left your book then get stash apply command is used to bring back we save the changes on to your current working directory the next question is what work is restored when the deleted branch is recovered so the files which were stashed and saved in this stash index list will be recovered back any untracked files will be lost also it is a good idea to always stage and commit your work or slash them so if you want to fetch the lock references of a particular branch or a tag then run the command get ref lock and the reference name so we will see about get off lock in the subsequent part of this session ok so the next question is explain the difference between git status and git diff so git diff depicts the changes between the commits commit and the working tree etc whereas git status shows you the difference between the working directory and the index git status is helpful in understanding get a bit more comprehensively git diff is similar to git status the only difference is that it shows the differences between the various commits and also between the working directory and the index the next question is mentioned the differences between the git clone and git remote so git remote creates an entry into your git config that specifies a name for a particular URL whereas get clone creates a new git repository by copying an existing one located at the URL the next question is what is get stashed wrong so good stash drop command is used to remove the stashed item it will remove the last added stash item by default and it can also remove a specific item if you include it as an argument the next question is how do you find a list of file that has changed in a particular comment so to get a list of file that has changed in a particular commit use the command as you can see here on this slide get diff 3 - R and the hash so given the commit hash this will list all the files that were changed or added in that the - our flag makes the command list individual files rather than collapsing them into the root directory names only you can also include the below mention point although it is totally optional but this will help you impress the interviewer so the output will also include some extra information which can be easily suppressed by including two flags so as you can see here on the screen this command here you have included two flags the no commit ID and the name only so here the no current ID will suppress the commit hashes from appearing in the output and the name only flag will only print the name of the files instead of their paths the next question is what is the function of get config so git uses your username to associate commits with an identity the git config command can be used to change your git configuration including your username so suppose you want to give a user name and an email ID to associate or commit with an identity so that you can know who has made a particular commit so for that there are two commands as you can see on the slide get config - - global user dot name and your name that you want to give to the user and then the email so the command for that is get conflict global user dot email and your email address so the next question is what does the command object contain so commit object basically contains three components first a set of files representing the state of a project at any given point of Bank the second one is the reference to the parent commit objects and the third one is an sha-1 name which is a 40 character string that uniquely identifies the commit object the next question is describe the branching strategies that you have used so this question is asked to test your branching experience with git so here we are going to discuss the three branches starting with the first one that is a feature branching so feature branch model keeps all of the changes for a particular feature inside of a branch when the feature is fully tested and validated by automated tests the branch is then merged into the master the second is the bass crunching in this model each task is implemented on its own branch with the task key included in the branch name it is easy to see which could implement switch tasks by just looking at the task key in the branch name and the third branching is their release branching once the develop branch has acquired enough features for a release you can clone that branch to formerly his branch creating this branch starts the next release cycle so no new features can be added after this point only bug fixes documentation generation and other release oriented tasks should go in this branch once it is ready to ship the release gets merged into the master and tagged without version number in addition it should be merged back into the develop branch which may have progressed since the release was initiated so this was about the branching strategies ok so the next question is explain the advantages of foking workflow there is a fundamental difference between the foking workflow and the other popular get workflows rather than using a single server side to act as a central codebase it gives every developer their own server-side repository the foking workflow is commonly seen in public open source projects a crucial advantage of foking workflow is that contributions can be generated even without needing everybody to push to a single central repository that leads to a clean project history developers can push to their own server-side repositories but only the project maintainer can push to the official repository if developers are ready to publish a local commit then they push the commit to their own public repository and not the official one so after this they go for a pull request with the main repository that lets the project maintainer know and update is ready to be integrated so these were a few advantages of foking workflow so the next question is how will you know in gate if a branch has already been merged into the master so the answer to this is pretty direct so there are two commands to check this the first command is the gate branch - - most so this command lists the branches that have been merged into the current branch and the second one is the gate branch - - no I moist so this command lists the branches that have not been merged the next question is why is it desirable to create an additional commit rather than amending an existing commit so there are two reasons for this question so the first one the amend operation destroys the state that was previously saved in a commit if there is just the commit message that is being changed then that is not a problem but if the contents are being amended then the chances of eliminating something important remains more the second reason is that abusing it - - amend command can result in the growth of a small commit and acquire unrelated changes the next question is what does hope comprise off in gate this directory consists of shell scripts that are activated if you run the corresponding gate commands for example git will try to execute the post commit script after you have run off commit the next question is in gate how would you return a commit that has just been pushed and made open so one or more commits can be reverted through the use of gate rebirth this command in a true sense creates a new commit with patches that cancel out the changes introduced in these specific commits if in case the commit that needs to be reverted has already been published or changing the repository history is not an option then in such cases get revert command can be used to revert the commits so alternatively there is always an option to check out the state of a particular comment from the past and committed a new the next question is how to remove a file from gate without removing it from your filesystem so one has to be very careful during a gate add else you may end up adding the files that you didn't want to commit however get RM command will remove it from both your staging area as well as your filesystem but this may not be what you want so instead you can use the command as you can see here get reset file or the Eco file name and dot git ignore so this means that git reset is exactly opposite to the git add command so the next question is could you explain the git workflow so to record the history of the project get workflow employees to parallel long-running branches the first one is the master branch and the second one is the develop branch so the master branch is always ready to be released on life with everything fully tested and approved that is production-ready state the hotfix branch in master is used to quickly patch the production release these branches are a lot like the release branches and the feature branches except that they are based on master instead of the develop and the second branch is the develop branch this is the branch to which all the future branches are most and where all the tests are performed only when everything's been thoroughly checked and fixed it can be merged into the master here there's one more branch called feature branch so each new feature should reside in its own branch which can be pushed to develop branch as their parent one so the next question is explained the difference between the head working tree and index so guys you can refer the diagram that is on your slide for clear understanding the working tree or the working directory or the workspace is the directory of source files that you are able to CM edit so the index or the staging area is a single large binary file which lists all the files in the current branch there sha-1 check sun's timestamps and the file name it is not another directory which contains a copy of files within it where as head is used to refer to the last commit in the currently checked out branch so the next question is what is the difference between folk branch and croon a folk is a copy of a repository normally you folk a repository so that you're able to freely experiment with changes without affecting the original project most commonly folks are either used to propose changes to someone else's project or to use someone else's project as a starting point of your own idea get cloning means pointing to an existing repository and make a copy of the repository in a new directory at some of the location the original repository can be located on the local file system or on the remote machine accessible supported protocols the git clone command is used to create a copy of an existing git repository in very simple word get branches are individual projects within a git repository different branches within a git repository can have completely different files and folders or it could have everything the same except for some lines of code in a particular the next question is what are the different ways by which you can refer to a commit so in get each commit has a unique hash these hashes are used to identify the corresponding commits in various scenarios for example while trying to check out a particular state of a court using the git checkout hash command along with this it maintains a number of elias's to certain commits known as the refs also every tag that is created in this repository effectively becomes a ref and that is exactly why you can use tags instead of committing hashes in various get commands so get also maintains a number of special Alice's that are changed based on the state of the repository so in gate commits are allowed to be referred to as relative to one another in case of most commits where the commit has two parents the race to sign can be used to select one of the two parents however these can also be used to refer to commits that reside on remote branches allowing one to control and manipulate them from the local gate environment the next question is what is the difference between rebasing and mosaic so in get the rebus command is used to integrate changes from one branch into another it is an alternative to the merge command the difference between rebasing and merging is that rebus rewrites the commit history in order to produce a straight linear succession of commits merging is gits way of putting a folk history back together again the git merge command helps you take the independent lines of development created by git branch and integrate them into a single branch the next question is mentioned the difference between revert and reset so reset is used to return the entire working tree to the last committed State this will scrub commits in a private branch or throw away uncommitted changes reset changes which commit a branch head is currently pointing at it alters the existing commit history so this command can also be used to unstaged files whereas get revert command creates a new commit that undergoes the changes from a previous commit so this command adds new history to the project it doesn't modify the existing history now we will talk about the advanced level of interview questions so the question here is how to squash slash n comments in + single comment so there are two options to squats last and commits into a single commit and you should mention both of these options while answering such questions so in the first option if you want to write the new commit message from scratch you should use the following command as you can see here on the screen get reset soft head and get commit and in the second option if you want to start editing the new commit message with a concatenation of the existing commit messages then you need to extract those messages and pass them to get commit and for this purpose you will use the command get reset soft head and this command get commit edit - him and the entire block command git log format reverse and the name of the head the next question is what is get bicep how can you use it to determine the source of a bug so get bicep is used to find the commit that introduced a buck by using a binary search so the command for get bicep is pretty simple as you can see on this slide get biceps sub command and the options this command uses a binary search algorithm to find out this commit in your projects history introduced a bug you can use it by first telling it a bad commit that is known to contain a bug and a good comment that is known to be before the bug was introduced then get bisect picks the commit between these two end points and asked you whether the selected commit is good or bad so it continues narrowing down the range until it finds the exact commit that introduced the change so the next question is how do you integrate get with Jenkins so as you can see on this slide these are the four steps that you can follow to integrate get with Jenkins and I am also going to show you the screenshots for these four steps so for anyone who's aware of Jenkins or has used Jenkins you must be aware of this homepage or the Jenkins dashboard so here you need to click on manage jenkins and once you click on manage jenkins you will find this option here the manage plugins option click on that and then you will have to search for the plug-in here as you can see in this screenshot click on this plug-in and here you have these two options installed without restart download now and install after restart so you can choose any one of them and once you are done with that you we'll be able to say this plugin that we have just downloaded along with its version number so these are the steps that you must follow to integrate get with Jenkins so the next question is how do you configure a repository to run or sanity checking tools right before making commits so here you must first mention what exactly is sanity checking a sanity or smoke test determines whether it is possible and reasonable to continue testing and now you must explain how do you achieve this so this can be done with a simple script related to the P commit hook of the repository the pre-commit hook is triggered right before a commit is made even before you are required to enter a commit message so in this script one can run other tools such as limiters and perform sanity checks on the changes being committed into the repository so as you can see here this is the script that I'm talking about the purpose of the script is that it checks to see if any dot go file that is about to be committed needs to be passed through the standard go source code formatting pulley by exiting to the non zero status the script effectively prevents the commit from being applied to the repository the next question is what is get cherry-pick the command git cherry-pick is normally used to introduce a particular commits from one branch within a repository on board different branch another common use of this command is to forward or back port commits from a maintenance branch or development branch this is in contrast with the other ways such as merge and rebase which normally apply many commits on to the another branch so the syntax for this command is very simple you just need to type git space cherry - pick space the commit hash the next question is what is get ref lock the ref low command keeps a track of every single change made in the references that is the branches or the tax of a repository and keeps a log history of the branches and the tags that were either created locally or checked out reference locks such as the commence snapshot of when the branch was created or clone checked out renamed or any comments made on the branch are maintained by git and listed by the ref lock command so this command must be executed in the repository that has the lost neurons so if you consider the remote repository situation then you have to execute the ref lock command on the developers machine who had the branch so the next question is how to recover a deleted branch using the get ref lock command so here as you can see on the screen these are the three steps that you must follow to recover a deleted branch and I'm also going to show you the screenshots okay so in the first step you get the history logs of all the references for that you just need to type get a ref log and once you type this command you can see the history log in the second step you need to identify the timestamp of the branch that you want to recover so here in this case this is the timestamp that we are looking for the pre prod branch here in the third step you just need to use the command git checkout - B and the branch name this is the point of reference when the P prod branch was created so if you follow these three steps you will be able to recover the deleted branch so the last question of this session that is mentioned some of the get ref locks subcommands so as you can see on the screen these are the commands that you will talk about four to five commands the first command is in traffic so this command is used to open up the manual page the second command is the gate tref lock show so this command shows the logs of the references provided in the command line the third command is the get rough Rock expire so this command is used to prune the older refract entries the fourth command is the get ref lock delete so as the name suggests this command deletes single entries from the error flock history and the fifth command is get ref lock exists so this command checks whether a reference that is a branch or a tag has a ref locked log history entries so these were a few commands like get ref lock sub commands that you can answer in this question so with this we have come to the end of this session I hope you have enjoyed this session if you have any queries related to this session you can post them in the comment box below and we will try to get back to you as early as possible I'll then happy learning thank you I hope you have enjoyed listening to this video please be kind enough to like it and you can comment any of your doubts and queries and we will reply them at the earliest do look out for more videos in our playlist and subscribe to any Rekha channel to learn more happy learning
Info
Channel: edureka!
Views: 54,329
Rating: 4.8591547 out of 5
Keywords: yt:cc=on, git interview questions and answers, git interview questions, top 50 git interview questions, frequently asked git interview questions, git interview questions for devops engineer, beginner git interview questions, intermediate git interview questions, advanced git interview questions, git interview questions edurekas, git tutorial, devops interview questions, git commit, github interview tips, git commit message, git commit and push, edureka, git edureka
Id: 8Xo3l1zv41I
Channel Id: undefined
Length: 33min 32sec (2012 seconds)
Published: Thu Oct 10 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.