Showing 30 question(s)

Answer:

Git is a distributed version control system used to track changes in source code during software development. It enables multiple developers to collaborate, maintain version history, and manage code efficiently.

Code Example:

git --version

Tags:

Answer:

Version control is a system that records changes to files over time, allowing developers to track modifications, collaborate, and restore previous versions when needed.

Code Example:

git init

Tags:

Answer:

Git provides fast performance, distributed development, branching, merging, complete history tracking, collaboration, and easy rollback to previous versions.

Code Example:

git log

Tags:

Answer:

A Git repository is a storage location that contains project files, commit history, branches, and Git metadata. Repositories can be local or remote.

Code Example:

git init

git clone https://github.com/user/repository.git

Tags:

Answer:

Git is a version control system used to track source code changes, whereas GitHub is a cloud-based platform that hosts Git repositories and provides collaboration features.

Code Example:

git remote -v

Tags:

Answer:

Use the git init command inside a project folder to create a new local Git repository.

Code Example:

mkdir MyProject
cd MyProject
git init

Tags:

Answer:

Use the git clone command followed by the repository URL to create a local copy of a remote repository.

Code Example:

git clone https://github.com/user/project.git

Tags:

Answer:

The git status command displays modified, staged, and untracked files in your repository.

Code Example:

git status

Tags:

Answer:

The working directory is the folder where you modify project files before staging and committing them to the repository.

Code Example:

git status

Tags:

Answer:

The staging area (also called the index) temporarily stores selected file changes before they are committed to the repository.

Code Example:

git add .
git status

Tags:

Answer:

A Git commit is a snapshot of the staged changes in your repository. Each commit has a unique hash and records who made the change, when it was made, and the commit message.

Code Example:

git commit -m "Initial commit"

Tags:

Answer:

Use the git add command to move changes from the working directory to the staging area before creating a commit.

Code Example:

git add file.txt

git add .

Tags:

Answer:

After staging files, use the git commit command with a descriptive message to save the changes permanently in the repository.

Code Example:

git commit -m "Added login feature"

Tags:

Answer:

The git log command displays the complete history of commits in the current branch.

Code Example:

git log

git log --oneline

Tags:

Answer:

A commit hash is a unique SHA-1 identifier generated by Git for every commit. It is used to reference specific commits.

Code Example:

git log --oneline

Tags:

Answer:

Use the git diff command to compare changes between the working directory, staging area, and previous commits.

Code Example:

git diff

git diff --staged

Tags:

Answer:

Use the git restore --staged command to unstage a file without losing your local changes.

Code Example:

git restore --staged file.txt

Tags:

Answer:

Use git commit --amend to modify the last commit by changing its message or including additional staged changes.

Code Example:

git commit --amend -m "Updated commit message"

Tags:

Answer:

Use the git show command followed by the commit hash to display detailed information about a specific commit.

Code Example:

git show <commit-hash>

Tags:

Answer:

git diff shows the actual code differences between versions, while git log displays the history of commits made in the repository.

Code Example:

git diff

git log --oneline

Tags:

Answer:

A Git branch is an independent line of development that allows developers to work on features, bug fixes, or experiments without affecting the main codebase.

Code Example:

git branch

Tags:

Answer:

Use the git branch command followed by the branch name to create a new branch.

Code Example:

git branch feature/login

Tags:

Answer:

Use the git switch or git checkout command to switch from one branch to another.

Code Example:

git switch feature/login

# Older command
git checkout feature/login

Tags:

Answer:

Use git switch -c or git checkout -b to create a new branch and immediately switch to it.

Code Example:

git switch -c feature/payment

# Older command
git checkout -b feature/payment

Tags:

Answer:

Use the git branch command to list local branches and git branch -a to list both local and remote branches.

Code Example:

git branch

git branch -a

Tags:

Answer:

Switch to the target branch and use the git merge command to merge changes from another branch.

Code Example:

git switch main

git merge feature/login

Tags:

Answer:

A merge conflict occurs when Git cannot automatically combine changes because the same lines of code were modified in different branches.

Code Example:

git status

git add .
git commit

Tags:

Answer:

Use git branch -d to delete a merged branch or git branch -D to force delete an unmerged branch.

Code Example:

git branch -d feature/login

git branch -D feature/login

Tags:

Answer:

Git Rebase moves or reapplies commits from one branch onto another, creating a cleaner and more linear commit history than a merge.

Code Example:

git switch feature/login

git rebase main

Tags:

Answer:

Merge combines branches while preserving commit history by creating a merge commit. Rebase rewrites commit history by placing commits on top of another branch, resulting in a cleaner linear history.

Code Example:

# Merge
git merge feature/login

# Rebase
git rebase main

Tags: