0% found this document useful (0 votes)
38 views7 pages

Git and Github

The document provides a comprehensive overview of Git, a distributed version control system, and its differences from other systems like SVN and GitHub. It outlines essential Git commands, concepts such as branching, merging, and conflict resolution, as well as advanced topics like rebasing and handling binary files. Additionally, it explains the purpose of .gitignore, Git hooks, and the use of Git in CI/CD pipelines.

Uploaded by

akashmishra7006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views7 pages

Git and Github

The document provides a comprehensive overview of Git, a distributed version control system, and its differences from other systems like SVN and GitHub. It outlines essential Git commands, concepts such as branching, merging, and conflict resolution, as well as advanced topics like rebasing and handling binary files. Additionally, it explains the purpose of .gitignore, Git hooks, and the use of Git in CI/CD pipelines.

Uploaded by

akashmishra7006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1.

What is Git, and how is it different from other version control systems like
SVN?

Git is a distributed version control system (DVCS) that allows multiple developers to work
on code simultaneously. Unlike SVN, which is centralized (relies on a central server), Git
allows every developer to have a full copy of the codebase locally, making it faster and more
reliable, especially when working offline.

2. What is the difference between Git and GitHub?

 Git is a command-line tool used for tracking changes in code.


 GitHub is a web-based platform that hosts Git repositories, enabling collaboration,
pull requests, and issue tracking.

3. What are the basic Git commands you use daily?

 git init – Initialize a repo


 git status – Check current state
 git add – Stage changes
 git commit – Save changes
 git push – Upload commits
 git pull – Download and merge changes
 git checkout – Switch branches
 git branch – Manage branches

4. What is the purpose of git init?

git init creates a new Git repository in your project directory, enabling version control for
that directory.

5. Explain the difference between git add, git commit, and git push.

 git add stages changes (prepares them to be committed)


 git commit saves those changes to your local repository
 git push sends the committed changes to a remote repository (e.g., GitHub)

6. What does git status show?


It displays the current state of your working directory and staging area. It tells you which files
are modified, staged, or untracked.

7. How do you create a new branch in Git?

You can create a new branch using:

bash
CopyEdit
git branch branch_name

Or, create and switch in one step:

bash
CopyEdit
git checkout -b branch_name

8. How do you switch between branches?

Use either:

bash
CopyEdit
git checkout branch_name

Or:

bash
CopyEdit
git switch branch_name

9. What is a merge conflict? How do you resolve it?

A merge conflict occurs when changes in two branches affect the same lines of code. Git
cannot merge them automatically.

To resolve:

 Manually edit conflicting files


 Use markers (<<<<<<<, =======, >>>>>>>) to identify conflicts
 Stage the resolved file: git add filename
 Complete merge: git commit

10. Explain git clone vs git pull.


 git clone copies a remote repository to your local machine.
 git pull fetches changes from the remote repo and merges them into your current
branch.

� Intermediate Level
11. What is the difference between git fetch and git pull?

 git fetch downloads changes from remote but does not merge them.
 git pull = git fetch + git merge. It automatically merges the changes into your
current branch.

12. How does git rebase differ from git merge?

 git merge combines histories, creating a merge commit.


 git rebase rewrites the commit history, making it linear by placing your changes on
top of the base branch.

13. What is the use of .gitignore?

.gitignore tells Git which files/folders to ignore (e.g., logs, temp files, build artifacts),
preventing them from being tracked or pushed.

14. What is a detached HEAD in Git?

A detached HEAD means you’re not on any branch. You’ve checked out a specific commit
instead. Any commits made here are not part of a branch and may be lost unless you create a
new branch.

15. How do you revert a commit?

Use:

bash
CopyEdit
git revert <commit_hash>

It creates a new commit that undoes the changes of the specified commit without changing
history.
16. How do you squash commits?

Squashing combines multiple commits into one:

bash
CopyEdit
git rebase -i HEAD~n

Then change pick to squash for the commits you want to combine, save, and edit the
commit message.

17. Explain git stash and how to use it.

git stash temporarily stores uncommitted changes so you can work on something else:

 Save: git stash


 Apply: git stash apply
 List: git stash list
 Delete: git stash drop

18. What is the difference between git reset, git checkout, and git revert?

 reset – Moves HEAD and optionally modifies index/working dir


 checkout – Switches branches or restores files
 revert – Safely undoes a commit by creating a new one

19. How can you view commit history in Git?

 git log – Shows full commit history


 git log --oneline – Compact view
 git log --graph – Visual graph

20. What is cherry-picking in Git?

It means applying a specific commit from one branch into another:

bash
CopyEdit
git cherry-pick <commit_hash>
� Advanced Level
21. What is Git rebase interactive (git rebase -i) and when do you use it?

Interactive rebase allows you to edit commit history, squash, reorder, or delete commits.
Useful for cleaning up commits before pushing to remote.

22. How do you resolve conflicts after a rebase?

 Fix conflicts in the files


 Stage them: git add file
 Continue rebase: git rebase --continue
 Abort if needed: git rebase --abort

23. How do you handle large binary files in Git?

Use Git LFS (Large File Storage):

bash
CopyEdit
git lfs install
git lfs track "*.psd"

24. How do you undo a pushed commit?

 Safe: git revert <commit> and push


 Force: git reset --hard HEAD~1 then git push --force (not recommended for
shared repos)

25. What are Git hooks?

Git hooks are scripts triggered by Git events like commit, push, merge. They automate tasks
(e.g., code formatting, testing).

26. How do you configure Git in a CI/CD pipeline?

 Clone the repo


 Install Git
 Run build/test scripts using Git commands
 Use tokens or SSH for authentication
27. What’s the difference between local, remote, and upstream branches?

 Local – Exists on your machine


 Remote – Exists on server (e.g., origin/main)
 Upstream – The remote branch your local branch tracks

28. How do you clean up a Git repository?

 Delete old branches: git branch -d branch_name


 Prune remote branches: git remote prune origin
 Clean files: git clean -f
 Remove large files: Git LFS or BFG Cleaner

29. Explain the concept of Git reflog.

git reflog shows the history of HEAD movements, even if commits are not visible in git
log. Useful for recovering lost commits.

30. What is the difference between origin/main and main?

 main – Your local branch


 origin/main – The remote-tracking branch from the server
They may differ if you haven't pulled/pushed recently.

Let me know if you'd like a PDF version or formatted cheat sheet of this!

You said:

stages means
ChatGPT said:

In Git, "staging" means preparing your changes to be committed.

� Think of Git as a 3-stage process:

1. Working Directory
This is where you make changes to your files (e.g., editing a file).
2. Staging Area (also called Index)
When you run git add, the changes go into the staging area — this means:

“I want these changes to be included in the next commit.”

3. Repository
When you run git commit, Git takes everything in the staging area and stores it
permanently in the local repository as a new commit.

� Example:
bash
CopyEdit
git add file.txt

This stages file.txt — it's ready to be committed.

bash
CopyEdit
git commit -m "Added changes to file.txt"

Now it's committed — saved in Git history.

� Summary:

 Staged = Ready for commit


 Unstaged = Modified but not marked for commit
 Committed = Saved in Git repo

Let me know if you’d like a diagram to visualize this!

You might also like