Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

3.GIT

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Entry-Level:

1. What is Git?
A version control system for tracking changes in source code during
software development.

2. What is GitHub?
GitHub is an internet hosting service that provides version control and
collaboration tools for developers.
3. Popular Git Hosting Services:

GitHub, GitLab, Bitbucket.


4. Different Types of Version Control:

1. Local: Has a database that stores all file changes under revision
control.
2. Centralized: Has a single repository - each user receives their
working copy (e.g., CVCS).
3. Distributed: Multiple repositories - different users can access each
one with their working copy (e.g., Git).
5. Difference Between Git and GitHub:
Git is the version control software, while GitHub is a web-based platform
that provides hosting for Git repositories.

6. Git Workflow:
1. Working Directory,--> local copy of your project
2. Staging Area, --> intermediate step where we can made changes
before commiting history
3. Repository.
Changes are made in the working directory, staged using git add to
move them to the staging area, and committed to the repository using
git commit.

7. Difference between Git and GitHub:

Git is a version control system, while GitHub is a web-based platform for


hosting Git repositories and collaborative development.
8. Difference between repository and branch in Git:

A repository is a container for project files and version history, while a


branch is a separate line of development within a repository.
9. Difference between git pull and git push:
git pull fetches changes and merges them into the current branch,
while git push uploads local changes to a remote repository.
10. Difference between git pull and git fetch:
git pull fetches and merges changes from a remote repository, while
git fetch only fetches changes, leaving the local branch unchanged.

11. Difference between git clone and git remote:


git clone copies a remote repository to create a local copy, while git
remote is used to manage remote repositories.

12. Difference between git diff and git status:


git diff shows changes between commits or branches, while git
status provides the status of the working directory, including untracked
files.
13. Difference between git merge and git rebase:
git mergecombines changes from different branches, creating a merge
commit, while git rebase integrates changes by moving or combining
commits from one branch to another.

14. Git repository and how to create it:


A Git repository is a storage location for a project's version-controlled
files. To create one, use: ```

15. Impact of directory deletion on Git repository:


Deleting a directory without using Git commands can result in untracked
changes. Use git rm to properly remove files and commit the changes.
16. Use of staging area or indexing in Git:
The staging area allows you to selectively prepare changes before
committing, providing control over what gets included in the next
commit.
17. Different Git repository hosting options:
Examples include GitHub, GitLab, Bitbucket, and others, providing
platforms for storing and collaborating on Git repositories.

18. Version control system definition:


Version control system (VCS) is a software tool that manages changes
to source code, allowing multiple contributors to work on a project
concurrently.

19. Advantages/features of Git:


Distributed version control, branching, merging, speed, and flexibility are
key advantages of Git.
Junior-Level:

1. What is a Repository?
A storage space where Git stores the history and multiple branches of
your project.
2. How to Initialize a Repository in Git:
Use the git init command.
3. Git vs Subversion (SVN):
Git is distributed and decentralized (each developer have complete copy
of repository), while SVN is centralized (Single repository).
Git - stores content in form of metadata SVN- stores data in form of files
4. What is a Commit?
A snapshot of changes made to a project; a save point in Git.
Mid-Level:

1. What is the Staging Area (Index)?


An intermediate area where changes are marked before committing to
the repository.
2. Git Workflow: Add, Commit, Push:
Add: Stage changes, Commit: Save changes locally, Push: Upload
changes to a remote repository.
3. How to Check the Status of Changes:
Use the git status command.
4. How to Merge Branches in Git:
Use the git merge command followed by the branch to be merged.
5. What is a Pull Request:
A request to merge changes from one branch into another; commonly
used in collaborative development.
6. Difference Between Git Pull and Git Fetch:
git pull fetches and merges changes, while git fetch only fetches
changes.
7. Explain Git Rebase:
Rewriting the commit history to produce a linear project history.
8. Git Submodule:
Allows you to include other Git repositories within your own repository.
9. How to Resolve Merge Conflicts:
Manually edit conflicted files, mark as resolved, and commit changes.
10. What is Git Cherry-Pick:
Applying a specific commit from one branch to another.
11. What is Git Bisect:
A binary search command to find the commit introducing a bug.
12. Explain Git Hooks:
Custom scripts triggered at specific points in the Git workflow.
13. How to Undo the Last Git Commit:
Use git reset HEAD~1 to undo the last commit while keeping changes.
14. Difference Between Head, Working Tree, Index:
Head points to the latest commit, Working Tree is the current state of
files, Index is the staging area.
15. How to Reverse the Previous Commit in Git:
Use git revert to create a new commit that undoes the changes
introduced by the previous commit.
16. Handling Sensitive Information in Git:
Remove the sensitive info from code, use git filter-branch or git
filter-repo to remove sensitive data from the entire commit history,
and force-push the corrected history to the remote repo. Communicate
the issue with other collaborators.

1. Command to set up Git username and email:


git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

2. Command to initialize a Git repository:


git init

3. Command to add files to the staging area in Git:


git add filename(s)

4. Command to commit changes with a message in Git:


git commit -m "Your commit message"

5. Command to see commit history in Git:


git log

6. Command to create a new branch in Git:


git branch branchname

7. Command to switch to another branch in Git:


git checkout branchname

8. Command to list branches in Git:


git branch

9. Command to create a branch and switch to it immediately:


git checkout -b newbranch

10. Command to delete a branch in Git:


git branch -d branchname

11. Command to merge two branches in Git:


git merge branchname

12. Command to abort a conflicting merge in Git:


git merge --abort

13. Command to pull or push changes in Git:


git pull origin branchname
git push origin branchname

14. Request in Git:


git request-pull origin/main mybranch

15. Command to add a remote repository in Git:


git remote add origin remote_repository_url

16. Command to rename files in Git:


git mv oldfilename newfilename
17. Command to ignore files in Git: Create a .gitignore file and add
filenames/patterns to be ignored.
18. Command to remove tracked files from the current working tree in Git:
git rm --cached filename

19. Command to rollback the last commit in Git:


git reset --hard HEAD^

20. How to fix a broken commit:


Amend the last commit using:
git commit --amend

1. Basic Commands:
ls: List files.
ls -a: List all, including hidden files.
git init: Initialize a .git file for project history.
git add <filename>: Stage files for commit.
git reset <filename> or git rm --cached <filename>: Unstage files.
git commit -m "<message>": Commit changes.

2. Status and Logs:

git status: Check staging status.


git log: View commit history with timestamps.
3. File Operations:

touch <filename>: Create a file with a specified extension.


cat <filename>: Display the content of a text file.

4. Git Stash:
git stash: Temporarily store changes.
git stash pop: Retrieve changes from stash.
git stash clear: Clear all changes from stash.

5. Remote Operations:
git remote add origin <link>: Link local repo to a remote repo.
git push origin master: Push changes to the master branch.

6. Branching:
git branch <name>: Create a new branch.
git checkout <branch>: Switch to a specified branch.
git merge <branch>: Merge changes from a branch.

7. Cloning and Forking:


git clone <url>: Clone a repository to the current directory.
Forking: Create a copy of a repository for independent work.
8. Pull Requests:
Create a new branch for each feature.
Make a pull request to propose changes.
Discuss, review, and merge changes.
9. Resetting and Force Push:
To undo commits: git reset <commit id>, git stash, and git push -f.
10. Fetch Upstream:
Update forked repositories with changes from the upstream: git fetch
--all --prune, git reset --hard upstream/main, and git push origin
main.

11. Merging Commits:


Combine commits: Use git rebase -i <commit id> for an interactive
environment, choose "squash" to merge.
12. Merging Conflicts:
Resolve conflicts when two people change the same line in the same
file during a merge.use pull requests for collaboration.

You might also like