git interview questions
git interview questions
1. What is git?
Git is nothing but Global Information Tracker.
Git is also called as version control system and source code management.
It is used to track the files.
It will maintain the multiple versions of the same file.
Git is free and open source.
Working directory: in this stage we can create a files for our project.
Repository: it is nothing but out project folder, when we commit the file it will
store on repository.
the data is safely stored in your local database.
Extra commands:
git show <commit> --stat : you’ll see the commit summary along with the files that
changed and details on how they changed.
git commit --amend -m “New commit message” : to edit the commit message
git commit --amend --no-edit : used to add some files in previous commit. (--no-
edit means that the commit message does not change.)
git update-ref -d HEAD : used to delete 1st commit in the git
git reset commit: used to delete all the commits (upto the commit id)
Let’s say that you forgot to configure the email and already did your first
commit. Amend can be used to change the author of your previous commit as well. The
author of the commit can be changed using the following command:
merge takes the changes from one branch and merges them into another branch in
one merge commit.
rebase adjusts the point at which a branch actually branched off (i.e. moves the
branch to a new starting point from the base branch).
Generally, you’ll use rebase when there are changes are made in main/master branch
that you want to include in your branch. You’ll use merge when there are changes in
a branch that you want to put back into main.
GITHUB
Git remote -v : used to see the remote repo
Git pull origin branch: used to get changes in GitHub
Git remote rename old -link new-link: change the repo
Git fetch origin master: to fetch from remote
Git merge origin/master : to merge from remote repo
git push origin --delete branch_name : to delete GitHub branch
Git fetch —all : used to fetch all the branches
git push -u origin --all : to push all branches
Git push -u origin branch1 branch2 : to push specific branches