This article was sponsored by Atlassian. Thank you for supporting the sponsors who make SitePoint possible.
Objective
Learn how to use pull requests for code review with Git by adding an inspirational quote to a teammate's repository.
Mission Brief
You've started getting the grasp of Git with a repository you own. But what if your team is off traveling the universe, and you want to be able to collaborate on the same repo? Complete this tutorial to learn the ropes of code review.
Topics covered:
- Forking a teammate's repository, creating a pull request, and contributing to a teammate's repository.
About Forking
When you work with another user's public Bitbucket repository, typically you have read access to the code but not write access. This is where the concept of forking comes in. Here's how it works:
- Fork the repository to copy it to your own account.
- Clone the forked repository from Bitbucket to your local system.
- Make changes to the local repository.
- Push the changes to your forked repository on Bitbucket.
- Create a pull request from the original repository you forked to add the changes you made.
- Wait for the repository owner to accept or reject your changes.
If a repository owner accepts the pull request, Bitbucket merges your code changes into the original repository. It is recommended that you work with forks and pull requests, even if the repository owner gives you write access to a public repository. While a pull is part of the Git and Mercurial workflow, pull requests and forks are concepts used only by repository hosting services — like Bitbucket.
Fork a Teammate's Repository
Since everyone on your team is not in the Bitbucket space station all at the same time, one of your team members decided it would be a neat idea to gather some inspiring quotes that anyone can refer to, whether they are making plans for the new space station on Saturn's rings or adventuring out to a new solar system! Your teammate started up a repository with the thought that anyone can contribute and inspire. You decide that you have a quote you want to add.
In this example you'll fork a public repository belonging to a user called tutorials
.
- Depending on which DVCS tool you are using, use the search field in the top right corner of Bitbucket to find one of the following repositories:
- For Git, search for the tutorials/tutorials.git.bitbucket.org repository.
- For Mercurial, search for the tutorials/tutorials.bitbucket.org repository.
- From the repository you open, click Fork on the left side of the screen. The system displays the fork page.
- Change the Name for example, to
myteamquotes
. - In the Description field, enter
Inspiring quotes for my team
. - Uncheck Inherit repository user/group permissions.
- Press Fork repository.
Copy Your Fork & Make a Change to the Repository
Have you figured out what piece of advice you want to share with your teammates yet? Let's get a copy of the forked repository to your local system so that you can add it.
I'm using Git!
Step 1. Clone your fork to your local system
- From the Overview page of the forked repository in Bitbucket, click Clone on the left side. The system displays a pop-up clone dialog. By default, the clone dialog sets the protocol to HTTPS unless you have already set up SSH for Git.
- From the pop-up clone dialog, copy the highlighted clone command.
- From your terminal window, change the directory to your
repositories
directory.$ cd ~/repos
- Paste the command you copied from Bitbucket onto the command line and press Return.
- Enter your Bitbucket password when the terminal asks for it. This is the password you entered when you created your Bitbucket account. If you created an account by linking to Google or Facebook, use your password for that account. At this point, your terminal window should look similar to this:
$ cd ~/repos $ git clone http://ift.tt/2mg8fvz Cloning into 'myteamquotes'... Password remote: Counting objects: 15, done. remote: Compressing objects: 100% (15/15), done. remote: Total 15 (delta 4), reused 0 (delta 0) Unpacking objects: 100% (15/15), done. Checking connectivity... done.
You now have the forked repository on your local system.
- From your terminal window, change the directory to your
Step 2. Make a change to the repository source
This repository contains a website that has an editme.html
file. This file lists inspirational quotes for your space teammates. Now, it is your turn to record an inspirational quote... or just a favorite quote. Do the following to contribute to this repository:
Continue reading %Learn About Code Review in Bitbucket Cloud%
by Atlassian via SitePoint
No comments:
Post a Comment