Best Practices for Branching and Merging in Software Development

Listen to this Post

URL: GitHub – jrebelo/demo_ntp

You Should Know:

1. Creating a New Branch in Git:

git checkout -b feature-branch

2. Committing Changes to a Branch:

git add .
git commit -m "Your commit message"

3. Pushing a Branch to Remote Repository:

git push origin feature-branch

4. Creating a Pull Request (PR) on GitHub:

  • After pushing your branch, go to GitHub and create a PR from your branch to the main branch.

5. Running Tests Before Merging:

npm test # For Node.js projects
pytest # For Python projects

6. Merging a Branch into Main:

git checkout main
git merge feature-branch

7. Resolving Merge Conflicts:

  • Open the conflicted file, resolve the conflict, then:
    git add <conflicted-file>
    git commit -m "Resolved merge conflict"
    

8. Enforcing Mandatory Checks with Git Hooks: