πŸš€ Mastering Git Branches and Pull Requests πŸš€

Β·

2 min read


πŸš€ Mastering Git Branches and Pull Requests πŸš€

Git branches and pull requests (PRs) are essential tools for collaboration in software development. Here’s a quick guide to help you understand and use them effectively! πŸ’‘

🌳 Understanding Git Branches:

Branches allow you to create a separate line of development, making it easy to work on new features, bug fixes, or experiments without impacting the main codebase.

Basic Commands for Branches:

  • Create a new branch:

      git branch new-branch-name
    
  • Switch to your new branch:

      git checkout new-branch-name
    

    or

      git switch new-branch-name
    
  • Create and switch to a new branch in one step:

      git checkout -b new-branch-name
    
  • List all branches:

      git branch
    
  • Delete a branch (after it’s merged):

      git branch -d branch-name
    

πŸ“₯ Creating a Pull Request (PR):

A pull request is a way to propose changes to the codebase. It's an invitation for other team members or maintainers to review your work before it gets merged.

Steps to Create a PR:

  1. Make sure you’re on the correct branch:

     git checkout new-branch-name
    
  2. Make your changes and commit them:

     git add .
     git commit -m "Description of changes"
    
  3. Push your branch to the remote repository:

     git push origin new-branch-name
    
  4. Create a Pull Request:

    • Go to the repository on GitHub (or your Git provider).

    • Navigate to the "Pull requests" tab.

    • Click on "New Pull Request" and select the branches you want to merge.

  5. Review and Merge:

    • Once approved, your changes can be merged into the main branch!

πŸ”„ Recap of Commands:

  • git branch to create and manage branches

  • git checkout or git switch to switch branches

  • git add, git commit to stage and commit changes

  • git push to push your branch

  • Create a pull request on the GitHub repository page

Mastering branches and pull requests will help you collaborate more effectively with your team and contribute to open source projects confidently! πŸš€

Happy coding! 😊


Β