So far, you've worked in a repository you own and you've been the only person working in it. You can only fully experience the power of a DVCS hosted repository by working with others. In this page, you work with a repository you don't own. You'll make a change to a code file, not just a README. You'll use Bitbucket's comparison features to compare your repository with the original.
The tutorial examples so far worked exclusively with Git repositories using
git commands. In this section, you'll work with a Mercurial repository. If you start working extensively in the host DVCS community, you'll most likely find yourself working with multiple DVC systems. You may even find yourself working with other hosted products, such as GitHub or Kiln. It is good experience to see the workflow you'd use in these types of situations.
The examples on this page work for Mecurial in a Mac OSX or Linux environment. If you want to work in TortoiseHg on Microsoft Windows 7, see the instructions on this page.
When you work with another user's public Bitbucket repo, typically you have read access to the code but not write access. This means that you can use a
clone command to copy the repo but you cannot
push changes to it. Instead, you use the Bitbucket interface to fork a repo. Bitbucket hosts private or public repos. Anyone can fork a public repo. You can fork a private repo where you have permissions.
Forking a repository creates a new repository under your account. This new repository is a copy of the original repo and is called a fork. Even though you have a fork, you can still get a change into the original repository, to do this you:
- clone the forked repo from Bitbucket to your local system
- make changes to the local repo
- push the changes to your fork on Bitbucket
- issue a pull request against the hosted repo you forked from
- wait for the repo owner to accept or reject your pull request
If a repo owner accepts a pull request, Bitbucket pulls your code changes into the original repo and merges them. Bitbucket recommends you work with forks and pull requests even if the repo owner gives you write access to a public repository. While a pull is a DVCS concept, "pull requests" and forks are concepts used only by repository hosting services — like Bitbucket and GitHub. You won't find fork and pull requests in any Git or Mercurial workflow that doesn't involve a repository hosting service.
Step 1. Fork another user's repo
In this example you'll fork a public repository belonging to a user called
- 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:
- 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
- In the Description field, enter
Inspiring quotes for my team.
- Uncheck Inherit repository user/group permissions.
- Press Fork repository.
Step 2. Clone your fork
- Open a terminal window on your local system.
- Change directory to your
If you have followed along in this tutorial, your repos folder contains only a single Git repository. There is no reason
reposcannot also contain a Mercurial repository.
Clone the fork to your local system.
The command is similar to the following:
You would need to replace
- Change to the
Step 3. Make a change to the repository source
This repository contains a website which, as of this writing, has a single
index.html file. Bitbucket allows you to host a website in a Mercurial repository. To see the hosted website, go to https://tutorials.bitbucket.org – you may encounter an Untrusted Connection message. Go ahead through to the site. You'll see that the site contains a single page that lists favorite quotes from "bitbuckians" which is just a writer-invented word for users of Bitbucket. Now, it is your turn to record your favorite comedic quote...or just a favorite quote. Do the following to contribute to this repository:
- Use Google or some other search engine to locate your favorite quote.
- Using your favorite editor, edit the
Add your favorite quote by copying and pasting another entry and replacing the details with your own quote. See the following example for the full tag to copy.
Be sure you paste the full tag structure and that you don't paste inside another tag or before the first <div> tag on the page.
You can also add a linked image file if you wish. We ask you do not add images to the tutorial repository but rather create a linked image as shown in the following example:
- Save and close the file.
Display the status of the repo:
If you added an image file, you'll see that as well.
Commit your changes locally, for example:
Push your changes to your Bitbucket fork.
Enter your password to finish pushing changes.
Step 4. Compare your fork to the original
While you were working on your fork, another Bitbucket user might have made updates to the original repository. At this point, you can check that and decide if you need to adjust your fork accordingly. Do the following to compare your changes with the repository:
- Log into Bitbucket and navigate to your
myquoteforkrepository. Forked repositories have a special widget that lets you compare your fork work to the original or to create a pull request.
- Click the Compare link on the left side of the page. The Compare section has a specialized view that is available only in forked repositories.
- Press the Compare button to compare your forked repository to the original repository.
- Click the Diff tab to compare changes from your fork to the original. If there are multiple commits, you see their cumulative changes by file in this section. Click the Side-by-side diff button to see changes displayed side-by-side. Or press the View file button to view the full file in Bitbucket.
- Switch back to the Compare tab to see the list of commits pushed from your local repository to the fork in Bitbucket. To see the contents of a specific commit in isolation, select a Commit link and the system takes you to the Commits page.
You can merge your fork into another repository — for example a local copy you may have of the original repository. If you merge locally, you can test your changes before making a pull request through Bitbucket.
Step 5. Create a pull request
If you haven't already done so, log into Bitbucket and navigate to your
myquotefork repository. Then, do the following:
- Press Create Pull Request.
The system displays the request form.
- Complete the form.
When you are done it will look something like this:
- Press Create pull request.
The system opens your latest request on the Pull Request page of the original repository. To see the list of all the pull requests against this repo, click the Pull Request tab.
Step 6. Learn what happens to your pull request
You have to wait for the repository owner to accept your pull request. When the original repository owner logs into Bitbucket, that user's newsfeed shows your pull request and your fork from a few days earlier, as shown in the following image.
When the repo owner clicks on your pull request, that user can Merge, Edit, or Decline (1) it. In addition to owners, anyone with access to the repository can Approve (2) the request, which means that the approver reviewed the changes in the pull request. The owner can also see any additional commits or activity (3) and how many files are in this pull request (4).
You'll get an email when your pull request is accepted. For now, continue onto the next section.
That was intense. Maybe. Depends on your daily life. In the next section, you learn ways to be social on Bitbucket which includes adding users to your repository.