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 --versionAnswer:
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 initAnswer:
Git provides fast performance, distributed development, branching, merging, complete history tracking, collaboration, and easy rollback to previous versions.
Code Example:
git logAnswer:
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.gitAnswer:
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 -vAnswer:
Use the git init command inside a project folder to create a new local Git repository.
Code Example:
mkdir MyProject
cd MyProject
git initAnswer:
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.gitAnswer:
The git status command displays modified, staged, and untracked files in your repository.
Code Example:
git statusAnswer:
The working directory is the folder where you modify project files before staging and committing them to the repository.
Code Example:
git statusAnswer:
The staging area (also called the index) temporarily stores selected file changes before they are committed to the repository.
Code Example:
git add .
git statusAnswer:
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"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 .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"Answer:
The git log command displays the complete history of commits in the current branch.
Code Example:
git log
git log --onelineAnswer:
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 --onelineAnswer:
Use the git diff command to compare changes between the working directory, staging area, and previous commits.
Code Example:
git diff
git diff --stagedAnswer:
Use the git restore --staged command to unstage a file without losing your local changes.
Code Example:
git restore --staged file.txtAnswer:
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"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>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 --onelineAnswer:
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 branchAnswer:
Use the git branch command followed by the branch name to create a new branch.
Code Example:
git branch feature/loginAnswer:
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/loginAnswer:
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/paymentAnswer:
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 -aAnswer:
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/loginAnswer:
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 commitAnswer:
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/loginAnswer:
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 mainAnswer:
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