SRE Bootcamp Series — Bitbucket Pull Requests
Hallo Geeks, I hope you feeling good and enjoy your entire life.
Now i’d like to convey to you:
- What is Pull-Request (PR)?
- Different way of making the pull requests in Bitbucket Repository
All of these knowledge is come from my ticket/sprint at AccelByte Inc.
Happy Reading guys!
What is Pull Request (PR)?
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.
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 by:
- forking the repository
- or 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:
- On bitbucket, fork the repository you want to contribute too.
- On bitbucket, clone your repository (the fork) to your computer.
- Make the changes to the project on your computer.
- Add and commit the changes on your computer.
- Push the changes back to your forked repository.
- On bitbucket, in the original repository, go to the Pull Request tab, click the “Create Pull Request” button.
- 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:
- Clone the bitbucket repository you want to contribute in a folder in your local/laptop.
git clone your-repo-link
git clone firstname.lastname@example.org:PATH_NAME/MY_REPO.git
Here is the result:
2. Make sure you’re on the right branch and in the project directory, on your local computer. if you don’t have any branch, please create your branch in bitbucket by clicking Create Branch button.
3. fill in the branch creation form.
4. Or you can also create a new branch for your changes, on your computer by this command:
git checkout -b your-branch-name
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.
5. In here, I create new branch from branch master in which:
- branch name: branch-test
- Type: feature
6. change your branch location, by default if you clone your file or project from your code repository to your local/laptop, by default it will be placed on branch: master. you can trace your current branch’s location by typing this command:
So, you have to change your branch location to your new branch which named by: branch-test.
git fetch && git checkout feature/branch-test
7. Make the changes to the project, on your local computer.
8. Add and commit the changes on your computer. (Make as many commits as you want.)
git add .
git commit -m "Added feature XYZ."
9. Push your changes to the bitbucket repository.
git push --set-upstream origin your-branch-name
10. In the repository in bitbucket, go to the ‘Pull requests’ tab, and click “Create pull request”.
From the picture below, you will see that after we create pull request, our code/feature which we commited will show at commit menu in bitbucket.
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.
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. My reason which I attached the pictures from google images is related to data-privacy and data credential from company which cannot be disseminated.
In the next article, we’ll look at how to make changes to the code in your Pull Request after making it. That’s all, Thank you!