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:

  • Create a pre-commit hook to run tests:
    </li>
    </ul>
    
    <h1>.git/hooks/pre-commit</h1>
    
    #!/bin/sh
    npm test
    

    9. Reverting a Broken Merge:

    git revert -m 1 <merge-commit-hash>
    

    10. Viewing Commit History:

    git log --oneline
    

    What Undercode Say:

    Branching and merging are fundamental practices in modern software development. By working in branches, you isolate your changes, reducing the risk of conflicts and broken code in the main branch. Enforcing mandatory checks before merging ensures that only tested and verified code makes it into the main branch, maintaining a stable and predictable development process.

    Here are some additional Linux and Windows commands that can help in managing your development environment:

    1. Linux Commands:

    • Check Disk Space:
      df -h
      
    • Search for Files:
      find /path/to/search -name "filename"
      
    • Monitor System Processes:
      top
      

    2. Windows Commands:

    • Check Disk Space:
      wmic logicaldisk get size,freespace,caption
      
    • Search for Files:
      dir /s /p "filename"
      
    • Monitor System Processes:
      tasklist
      

    By following these best practices and utilizing these commands, you can maintain a robust and efficient development workflow, ensuring that your codebase remains stable and reliable.

    References:

    Reported By: Joao Rebelo – Hackers Feeds
    Extra Hub: Undercode MoN
    Basic Verification: Pass ✅Featured Image