Git Best Practices Flashcards
Q: What is a good practice for commit messages?
A: Use clear, concise messages describing the purpose of the changes (e.g., “Fix login bug in authentication module”).
Q: How should you format commit messages?
A: Use a short summary (50 characters or less), followed by a detailed description if needed.
Q: Why is it important to make small, incremental commits?
A: It makes it easier to understand and debug the changes in the project history.
Q: When should you use branches?
A: Use branches for new features, bug fixes, or experiments to keep the main branch stable.
Q: What is the purpose of a branch naming convention?
A: It makes branches easy to identify, e.g., feature/login, bugfix/auth-error, or hotfix/v1.0.1.
Q: How often should you pull changes from the remote repository?
A: Frequently, to stay up-to-date with the latest changes and avoid conflicts.
Q: Why should you rebase instead of merge for small feature branches?
A: Rebasing keeps the commit history linear and clean.
Q: When is it better to use git merge over git rebase?
A: Use merge for long-lived branches like main to preserve the commit history.
Q: How can you avoid committing sensitive information?
A: Use a .gitignore file to exclude sensitive files and directories.
Q: What is the best practice for managing .gitignore files?
A: Create project-specific .gitignore files and use a global ignore file for personal patterns.
Q: Why should you avoid using git push –force?
A: It can overwrite changes on the remote and disrupt collaboration.
Q: When is it acceptable to use git push –force?
A: On private branches that are not shared with others or when explicitly coordinated with the team.
Q: What is a good practice for tagging?
A: Use tags to mark release versions (e.g., v1.0.0, v2.1.3).
Q: How should you structure your branches in a large project?
A: Use Git workflows like Gitflow or trunk-based development to organise branches efficiently.
Q: Why should you test code before committing?
A: To ensure that the code is functional and reduces errors introduced into the repository.