Top 20 [amazon_textlink asin=’B01ISNIKES|1449316387′ text=’GIT ‘ template=’ProductLink’ store=’desibanjara22-21|desibanjaraco-21′ marketplace=’IN|UK’ link_id=’68a83645-0879-11e9-9eea-b3538ea6ba7b’] interview questions:
- What is a repository in GIT?
Git stores this information in a data structure called a repository. 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.
- How can you create a repository in Git?
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.
- What is git clone command do?
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.
- What is the command you can use to write a commit message?
The command that is used to write a commit message is “git commit –a”.
–a option instructs git to commit the new content of all tracked files that have been modified.
- What is ‘git push’ in GIT?
‘git push’ updates remote refs along with associated objects.
git push –f option you can use to do force push
- What is another option for merging?
“Rebasing” is an alternative to merging in git.
- What is “Rebasing” and what is the syntax for “Rebasing” in Git?
git rebase is a command which will merge another branch into the branch where you are currently working, and move all of the local commits that are ahead of the rebased branch to the top of the history on that branch.
The syntax for rebase is
“git rebase [new-commit] “
- What is GIT stash?
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.
Example if you want to rebase with develop but you have some local changes. You can stash it first and then do the rebase. Once you will be happy with rebase. You can do “stash pop” to get that changes back in your branch. Steps below:
git stash
git stash list
git checkout develop
git pull
git checkout feature-nhso-3227-emis-linkage-status-codes
git rebase develop
git status
git stash pop
- What is GIT stash drop?
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.
- What is the difference between ‘git remote’ and ‘git clone’?
‘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.
[amazon_link asins=’1449325866′ template=’ProductAd’ store=’desibanjara22-21′ marketplace=’IN’ link_id=’29351ecb-087a-11e9-b084-c1b28661d721′]
[amazon_link asins=’1449325866′ template=’ProductAd’ store=’desibanjaraco-21′ marketplace=’UK’ link_id=’29351ecb-087a-11e9-b084-c1b28661d721′]
- What is the function of ‘git diff ’ in git?
‘git diff ’ shows the changes between commits, commit and working tree etc.
- What is ‘git status’ is used for?
As ‘Git Status’ shows you the difference between the working directory and the index, it is helpful in understanding a git more comprehensively.
- What is the difference between the ‘git diff ’and ‘git status’?
‘git diff’ is similar to ‘git status’, but it shows the differences between various commits and also between the working directory and index.
- What is the function of ‘git checkout’ in git?
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.
- What is the function of ‘git rm’?
To remove the file from the staging area and also off your disk ‘git rm’ is used.
- What is the function of ‘git stash apply’?
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.
- What is the use of ‘git log’?
To find specific commits in your project history- by author, date, content or history ‘git log’ is used.
- What is ‘git add’ is used for?
‘git add’ adds file changes in your existing directory to your index.
- What is the function of ‘git reset’?
The function of ‘Git Reset’ is to reset your index as well as the working directory to the state of your last commit.
reset git branch to origin version:
git checkout mybranch
git reset –hard origin/mybranch
- How will you know in GIT if a branch has been already merged into master?
Git branch—merged lists the branches that have been merged into the current branch
Git branch—-no merged lists the branches that have not been merged
[amazon_link asins=’1787120724,B0769JLP9C,1449325866,B01ISNIKES,8132231937,B07CDV9LJD,B00QFIA5OC,1782168451,1783553758′ template=’ProductGrid’ store=’desibanjara22-21′ marketplace=’IN’ link_id=’75aeb652-0879-11e9-aaed-6744dc20efd0′]
[amazon_link asins=’1449316387,1617292419,1789137543,B00QFIA5OC,1449325866,B01GO8ZVFA,1491911182,1978117515,1484200772′ template=’ProductGrid’ store=’desibanjaraco-21′ marketplace=’UK’ link_id=’9997ad94-0879-11e9-bc08-4dbf6eb24b6c’]