Branching and Merging Flashcards

1
Q

Q: What is a branch in Git?

A

A: A branch is a separate line of development, allowing you to work on different features or fixes independently.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Q: How do you list all branches in a repository?

A

A: Use git branch to list local branches and git branch -r for remote branches.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Q: How do you create a new branch?

A

A: Use git branch <branch-name>.</branch-name>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Q: How do you switch to an existing branch?

A

A: Use git checkout <branch-name> or git switch <branch-name>.</branch-name></branch-name>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Q: How do you create and switch to a new branch in one command?

A

A: Use git checkout -b <branch-name> or git switch -c <branch-name>.</branch-name></branch-name>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Q: How do you delete a branch locally?

A

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>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Q: How do you rename a branch?

A

A: Use git branch -m <old-name> <new-name>.</new-name></old-name>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Q: How do you push a new branch to a remote repository?

A

A: Use git push -u origin <branch-name>.</branch-name>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Q: How do you delete a branch on a remote repository?

A

A: Use git push origin –delete <branch-name>.</branch-name>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Q: What is the default branch in most Git workflows?

A

A: The default branch is typically named main or master.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Q: How do you merge a branch into the current branch?

A

A: Use git merge <branch-name>.</branch-name>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Q: What is a fast-forward merge?

A

A: A fast-forward merge occurs when the branch being merged has no additional commits, so the branch pointer is simply moved forward.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Q: How do you force a merge commit even if it can be fast-forwarded?

A

A: Use git merge –no-ff <branch-name>.</branch-name>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Q: How do you resolve a merge conflict?

A

A: Manually edit conflicting files, stage the changes with git add, and then commit.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Q: How do you view conflicts during a merge?

A

A: Look for conflict markers in the affected files («««<, =======,&raquo_space;»»>).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Q: How do you abort an ongoing merge?

A

A: Use git merge –abort.

17
Q

Q: How do you check which branch you are currently on?

A

A: Use git branch or git status.

18
Q

Q: What is the HEAD pointer in Git?

A

A: HEAD points to the current branch or commit you are working on.

19
Q

Q: How do you check the merge base of two branches?

A

A: Use git merge-base <branch1> <branch2>.</branch2></branch1>

20
Q

Q: What is a feature branch?

A

A: A feature branch is a branch used to develop a specific feature independently before merging it into the main branch.

21
Q

Q: How do you rebase a branch onto another branch?

A

A: Use git rebase <branch-name> while on the branch you want to rebase.</branch-name>

22
Q

Q: What is the difference between merging and rebasing?

A

A: Merging combines branches while preserving their commit histories. Rebasing rewrites commit history to create a linear sequence.

23
Q

Q: How do you continue a rebase after resolving conflicts?

A

A: Use git rebase –continue.

24
Q

Q: How do you cancel an ongoing rebase?

A

A: Use git rebase –abort.

25
Q

Q: How do you create a branch that tracks a remote branch?

A

A: Use git checkout -b <branch-name> origin/<branch-name> or git switch --track origin/<branch-name>.</branch-name></branch-name></branch-name>