Branching and Merging Flashcards
Q: What is a branch in Git?
A: A branch is a separate line of development, allowing you to work on different features or fixes independently.
Q: How do you list all branches in a repository?
A: Use git branch to list local branches and git branch -r for remote branches.
Q: How do you create a new branch?
A: Use git branch <branch-name>.</branch-name>
Q: How do you switch to an existing branch?
A: Use git checkout <branch-name> or git switch <branch-name>.</branch-name></branch-name>
Q: How do you create and switch to a new branch in one command?
A: Use git checkout -b <branch-name> or git switch -c <branch-name>.</branch-name></branch-name>
Q: How do you delete a branch locally?
A: Use git branch -d <branch-name> for a merged branch or git branch -D <branch-name> for an unmerged branch.</branch-name></branch-name>
Q: How do you rename a branch?
A: Use git branch -m <old-name> <new-name>.</new-name></old-name>
Q: How do you push a new branch to a remote repository?
A: Use git push -u origin <branch-name>.</branch-name>
Q: How do you delete a branch on a remote repository?
A: Use git push origin –delete <branch-name>.</branch-name>
Q: What is the default branch in most Git workflows?
A: The default branch is typically named main or master.
Q: How do you merge a branch into the current branch?
A: Use git merge <branch-name>.</branch-name>
Q: What is a fast-forward merge?
A: A fast-forward merge occurs when the branch being merged has no additional commits, so the branch pointer is simply moved forward.
Q: How do you force a merge commit even if it can be fast-forwarded?
A: Use git merge –no-ff <branch-name>.</branch-name>
Q: How do you resolve a merge conflict?
A: Manually edit conflicting files, stage the changes with git add, and then commit.
Q: How do you view conflicts during a merge?
A: Look for conflict markers in the affected files («««<, =======,»_space;»»>).