Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

git interview questions

Git is a free and open-source version control system used to track changes in files and maintain multiple versions. It operates through three stages: working directory, staging area, and repository, and includes commands for tracking, committing, merging, and resolving conflicts. GitHub is a web-based service for hosting Git repositories, with distinct features compared to Git, such as repository types and default branches.

Uploaded by

Rakesh Mirchi
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

git interview questions

Git is a free and open-source version control system used to track changes in files and maintain multiple versions. It operates through three stages: working directory, staging area, and repository, and includes commands for tracking, committing, merging, and resolving conflicts. GitHub is a web-based service for hosting Git repositories, with distinct features compared to Git, such as repository types and default branches.

Uploaded by

Rakesh Mirchi
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

GIT:

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.

2. What are git stages?

There are 3 stages in git which is


1. Working directory
2. Staging areas
3. Repository

Working directory: in this stage we can create a files for our project.

Staging area: it is nothing but a rough draft space


We can modified file in its current version to go into your next commit snapshot.
We can track the files in staging area.

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.

We have 3 types of repositories


1. Local
2. Remote
3. Central

3. How to track a file in git?


To track a file, we use a command “git add filename”
Once we add, it will gets started tracking
So that we can know the every modification on the file

4. How to commit the file?


To commit a file we use a command called “git commit -m “message” file_name
Once we commit the file it will safely stored in local database.

5. What is git status?


Git status is used to know the tracking and untacking files in our server.

6. What is git logs?


Git log is a history, we can see the list of every commit in our project along some
other information like who commit the file and when we commit the file.

7. How to configure in git


Git config user.name “name”
Git confit user.email “name@gmail.com”

8. What is git merge?


It allows us to get the code from one branch to another. This is useful when
developers work on the same code and want to integrate their changes before pushing
them up in a branch.

Command: git merge branch_name


9. What is merge conflicts?
Merge conflicts happen when you merge branches that have competing commits, and Git
needs your help to decide which changes to incorporate in the final merge.

10. What is git diff?


It is used to show all the differences between any two commits or files within your
Git repository.

11. What is git push?


Git push is used to share the local files into central repositories like GitHub and
Bitbucket.

12. What is git stash?


It is used to save your changes but not record them in the Git repository.

13. What is git clone?


Git clone is used to get the repository from central to local.

14. What is Git checkout?


Git checkout is used to switch the branches

Command: git checkout branch_name

15. What is git rm?


Git rm is used to untrack the files

16. Difference b/w git and GitHub?


Git is a software GitHub is a service
Git can be installed locally on the system GitHub is hosted on the web
Git has 3 types of repositories GitHub has 2 types of repositories
Git has a default branch called master GitHub has a default branch called main

17. What is git pull?


Git pull is the combination of git fetch and git merger
Git pull is used to get the commits from central repo to local repo

Command: git pull origin branch

18. Git fetch vs pull

Git Fetch Git Pull


The Git fetch command only downloads new data from a remote repository. Git
pull updates the current HEAD branch with the latest changes from the remote
server.
It does not integrate any of these new data into your working files. Downloads
new data and integrate it with the current working files.
Command - git fetch origin
git fetch --all Tries to merge remote changes with your local ones.
Command - git pull origin master

19. How to resolve the git conflicts?


* Open the file in vi editor and remove the conflict messages.
* Save the file
* Add the files using the git add command.
* The last step is to commit the changes in the file.

20. What is git tag?


Tagging is generally used to capture a point in history that is used for a marked
version release.

21. How to change the commit message


git commit —amend commit_id

22. What is git fork?


Git fork is used to get the repositories from another account

23. What is cherry-pick?


Cherry-pick is used to get a particular file from another branch
command: git cherry-pick commit_id

24. What is git branch?


A branch is a way to isolate development work on a particular aspect of a project.

25. What is git blame?


It is used to see the history of the GitHub file.
===================================================================================
=======

Git reset commit_id : deletes the commits


git log --graph --oneline --all : see all the history in graph
git merge --abort : cancel the conflicts in commits
git remote show origin : used to see the branches in GitHub
git log origin/main : history of the GitHub
git push --delete origin mustafa : delete the branch on GitHub
Git branch -m old new : to change the branch name

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:

git commit --amend --author "Author Name <Author Email>"

git merge vs git rebase


When there are changes on the main branch that you want to incorporate into your
branch, you can either merge the changes in or rebase your branch from a different
point.

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

You might also like