Bitbucket Pull Requests: The Fork Way, and The Branch Way

Bitbucket Pull Requests: The Fork Way, and The Branch Way

Introduction

A pull request is a way for you to contribute to a project by making changes to the code of a project, and then asking the repository owner to merge your changes with the current main project.

​We’ve done a blogpost on pull requests for github, so in this post we’ll look at pull requests bitbucket. There’s a different etiquette for bitbucket pull requests compared to github, so we’ll need to use a different way of making the pull requests. The two ways that we can raise a pull request on bitbucket are (1) by forking the repository, or (2) by making a new branch.

The Fork Way

On the bitbucket website, you can fork a repository (making a copy of your own), make your changes to your personal version of the repository, and then go back to the original repository and raise the pull request, offering your version of the code to the original repository.

This is very good for open source projects, which github is famous for, but isn’t as good for bitbucket. Nevertheless, the process is:

  1. On bitbucket, fork the repository you want to contribute too.
  2. On bitbucket, clone your repository (the fork) to your computer.
  3. Make the changes to the project on your computer.
  4. Add and commit the changes on your computer.
  5. Push the changes back to your forked repository.
  6. On bitbucket, in the original repository, go to the Pull Request tab, click the “Create Pull Request” button.
  7. Select your forked repository, write your description, and submit it to be reviewed.

This method works, but has a lot of drawbacks. The next way to make a Pull Request is the preferred method.

The Branch Way (Preferred)

If your project is on bitbucket, then you’re likely working on a small-ish team with other people. This means that you have more freedom to edit the actual project, and so forking is unnecessary. (Your boss probably doesn’t want random forks of the project all over the place. And even if your code doesn’t get merged immediately, it should be part of the main project for other people to see.) For this reason, creating a branch on the project repository and making the pull request from that branch is best practice.

The process for making a pull request via making a new branch is:1. Clone the bitbucket repository you want to contribute too.

git clone repolinkhere

2. (Make sure you’re on the right branch and in the project directory, on your local computer.)

git checkout thebranchnamehere

3. Make the changes to the project, on your local computer.
​4. Add and commit the changes on your computer. (Make as many commits as you want.)

git add .
git commit -m "Added feature XYZ."

5. Create a new branch for your changes, on your computer.

git checkout -b yourbranchname

Note: Make your branch name descriptive. For example, naming it “feature/XYZ” if it’s a new feature and is about XYZ is easy to let anyone know what the branch is for.7. Push your changes to the bitbucket repository. 

git push --set-upstream origin yourbranchname

8. In the repository in bitbucket, go to the ‘Pull requests’ tab, and click “Create pull request”.And your PR is created. Using branches is pretty simple, and much cleaner than forking. All professional teams should be handling their pull requests this way.

Conclusion

Pull Requests on bitbucket are pretty easy. Make sure you use the branching technique when possible, though, as it becomes very relevant when wanting to edit your Pull Request.



Leave a Reply

Your email address will not be published.

*
*
*