Git Best Practices Flashcards

1
Q

Q: What is a good practice for commit messages?

A

A: Use clear, concise messages describing the purpose of the changes (e.g., “Fix login bug in authentication module”).

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

Q: How should you format commit messages?

A

A: Use a short summary (50 characters or less), followed by a detailed description if needed.

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

Q: Why is it important to make small, incremental commits?

A

A: It makes it easier to understand and debug the changes in the project history.

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

Q: When should you use branches?

A

A: Use branches for new features, bug fixes, or experiments to keep the main branch stable.

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

Q: What is the purpose of a branch naming convention?

A

A: It makes branches easy to identify, e.g., feature/login, bugfix/auth-error, or hotfix/v1.0.1.

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

Q: How often should you pull changes from the remote repository?

A

A: Frequently, to stay up-to-date with the latest changes and avoid conflicts.

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

Q: Why should you rebase instead of merge for small feature branches?

A

A: Rebasing keeps the commit history linear and clean.

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

Q: When is it better to use git merge over git rebase?

A

A: Use merge for long-lived branches like main to preserve the commit history.

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

Q: How can you avoid committing sensitive information?

A

A: Use a .gitignore file to exclude sensitive files and directories.

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

Q: What is the best practice for managing .gitignore files?

A

A: Create project-specific .gitignore files and use a global ignore file for personal patterns.

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

Q: Why should you avoid using git push –force?

A

A: It can overwrite changes on the remote and disrupt collaboration.

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

Q: When is it acceptable to use git push –force?

A

A: On private branches that are not shared with others or when explicitly coordinated with the team.

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

Q: What is a good practice for tagging?

A

A: Use tags to mark release versions (e.g., v1.0.0, v2.1.3).

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

Q: How should you structure your branches in a large project?

A

A: Use Git workflows like Gitflow or trunk-based development to organise branches efficiently.

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

Q: Why should you test code before committing?

A

A: To ensure that the code is functional and reduces errors introduced into the repository.

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

Q: How can you ensure consistent code quality in a team?

A

A: Use Git hooks for pre-commit or pre-push checks, such as linting and unit tests.

17
Q

Q: What is the best way to handle merge conflicts?

A

A: Resolve them promptly, review the changes carefully, and test the code after resolving.

18
Q

Q: Why should you avoid committing generated files or build artifacts?

A

A: They can bloat the repository and are better recreated by the build system.

19
Q

Q: What is the purpose of a code review?

A

A: To ensure code quality and catch potential bugs or issues before merging changes.

20
Q

Q: Why should you periodically clean up old branches?

A

A: To keep the repository tidy and avoid confusion over obsolete branches.

21
Q

Q: How should you organise commits when preparing for a merge request?

A

A: Squash or rebase commits into logical, meaningful units for easier review.

22
Q

Q: Why is it important to use descriptive branch names?

A

A: It helps the team understand the purpose of the branch at a glance.

23
Q

Q: What is a good practice for managing remote repositories?

A

A: Regularly prune unused remotes with git remote prune origin.

24
Q

Q: How can you improve collaboration in a team using Git?

A

A: Use clear workflows, consistent naming conventions, and frequent communication about branch activity.

25
Q

Q: Why should you document your Git workflow?

A

A: To ensure everyone on the team follows the same practices and understands the process.