Skip to content

Commit

Permalink
Merge pull request #17 from douglatornell/bitbucket-setup
Browse files Browse the repository at this point in the history
Improve flow of 1st push to Bitbucket & use `hg config --local` command.
  • Loading branch information
douglatornell committed May 15, 2015
2 parents 246991e + 3214a33 commit 2ec9924
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 35 deletions.
119 changes: 85 additions & 34 deletions 02-collab.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,106 @@ Systems like Mercurial allow us to move work between any two repositories.
In practice, though,
it's easiest to use one copy as a central hub,
and to keep it on the web rather than on someone's laptop.
Most programmers use hosting services like [BitBucket](http://bitbucket.org)
Most programmers use hosting services like [Bitbucket](http://bitbucket.org)
and similar to hold those master copies;
we'll explore the pros and cons of this in the final section of this lesson.

Let's start by sharing the changes we've made to our current project with the world.
Log in to BitBucket,
Log in to Bitbucket,
then click on the icon in the top right corner to create a new repository called `planets`:

![Creating a Repository on BitBucket (Step 1)](fig/bitbucket-create-repo-01.png)
![Creating a Repository on Bitbucket (Step 1)](fig/bitbucket-create-repo-01.png)

Name your repository "planets" and then click "Create Repository":

![Creating a Repository on BitBucket (Step 2)](fig/bitbucket-create-repo-02.png)
![Creating a Repository on Bitbucket (Step 2)](fig/bitbucket-create-repo-02.png)

As soon as the repository is created,
BitBucket displays a page with a URL and some information on how to configure your local repository:
Bitbucket displays a page with a URL and some information on how to configure your local repository:

![Creating a Repository on BitBucket (Step 3)](fig/bitbucket-create-repo-03.png)
![Creating a Repository on Bitbucket (Step 3)](fig/bitbucket-create-repo-03.png)

Select "I have an existing project" and follow its instructions.
From within your `planets` directory, issue
Select "I have an existing project".
We're going to use a slight variation on those instructions.
From within your `planets` directory,
issue a command like:

hg push ssh://[email protected]/vlad/planets
~~~ {.bash}
$ hg push https://bitbucket.org/vlad/planets
~~~

It's similar to the one shown under "I have an existing project" on the Bitbcucket page,
but the URL should have your Bitbucket user name in it instead of `vlad`,
and be prefixed with `https://`, not `ssh://hg@`.

The output from that command should look like:

This brings the repository on BitBucket's server up-to-date with
~~~ {.output}
pushing to https://bitbucket.org/vlad/planets
searching for changes
http authorization required for https://bitbucket.org/vlad/planets
realm: Bitbucket.org HTTP
user: vlad
password:
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added 3 changesets with 3 changes to 1 files
~~~

You will have to type your own Bitbucket user name and password.

This brings the repository on Bitbucket's server up-to-date with
the one on our own machine.
Our local and remote repositories are now in this state:

![Bitbucket Repository After First Push](fig/bitbucket-repo-after-first-push.svg)

The next step is to connect the two repositories.
We do this by making the BitBucket repository a **remote**
The next step is to connect the two repositories so that we don't have to type the URL every time we do something with Bitbucket.
We do this by making the Bitbucket repository a **remote**
for the local repository.
You'll need the URL for the Bitbucket repository, which is the
same URL from the `hg push` statement above.

You'll need the URL for the BitBucket repository, which is the
same URL from the `hg push` statement above, but with the leading
`ssh://hg@` replaced with `https://`. Create a file `.hg/hgrc` in your
local repository, and use your text editor to create a
`[paths]` section in it, like so:
Use the command:

~~~ {.bash}
$ hg config --local
~~~

to open your local repository's configuration file in your editor.
You should see a template file that looks like:

~~~
# example repository config (see "hg help config" for more info)
[paths]
# path aliases to other clones of this repo in URLs or filesystem paths
# (see "hg help config.paths" for more info)
#
# default = http://example.com/hg/example-repo
# default-push = ssh://[email protected]/hg/jdoes-fork
# my-fork = ssh://[email protected]/hg/jdoes-fork
# my-clone = /home/jdoe/jdoes-clone
[ui]
# name and email (local to this repository, optional), e.g.
# username = Jane Doe <[email protected]>
~~~

Edit the file so that it has just 2 lines:

~~~
[paths]
default = https://bitbucket.org/vlad/planets
~~~

Make sure to use the URL for your repository rather than Vlad's
and to prefix the URL with `https://`, not `ssh://hg@`.
(the one from the `hg push` command above),
and that the prefix in the URL is `https://`,
not `ssh://hg@`.

Save the file.
It will automatically be stored in `planets/.hg/hgrc`.

We can check that the command has worked by running `hg paths`:

Expand All @@ -74,25 +130,20 @@ default = https://bitbucket.org/vlad/planets
~~~

Now that the default path is set up, we won't need to specify the
target when we run `hg push` in the future; running `hg push`
target URL when we run `hg push` in the future; running `hg push`
will automatically push the changes from our local repository
to the repository on BitBucket:
to the repository on Bitbucket:

~~~ {.bash}
$ hg push
~~~
~~~ {.output}
pushing to https://bitbucket.org/vlad/planets
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files
no changes found
~~~

Our local and remote repositories are now in this state:

![BitBucket Repository After First Push](fig/bitbucket-repo-after-first-push.svg)
This push has no effect because the two repositories are already synchronized.

We can pull changes from the remote repository to the local one as well:

Expand All @@ -107,7 +158,7 @@ no changes found

Pulling has no effect in this case
because the two repositories are already synchronized.
If someone else had pushed some changes to the repository on BitBucket,
If someone else had pushed some changes to the repository on Bitbucket,
though,
this command would download them to our local repository.

Expand All @@ -117,7 +168,7 @@ To do this,
(Note the absolute path:
don't make `tmp` a subdirectory of the existing repository).
Instead of creating a new repository here with `hg init`,
we will **clone** the existing repository from BitBucket:
we will **clone** the existing repository from Bitbucket:

~~~ {.bash}
$ cd /tmp
Expand Down Expand Up @@ -145,7 +196,7 @@ $ hg add pluto.txt
$ hg commit -m "Some notes about Pluto"
~~~

then push the change to BitBucket:
then push the change to Bitbucket:

~~~ {.bash}
$ hg push
Expand Down Expand Up @@ -243,9 +294,9 @@ to share work between different people and machines.

> ## Bitbucket Timestamp {.challenge}
>
> Create a repository on BitBucket,
> Create a repository on Bitbucket,
> clone it,
> add a file,
> push those changes to BitBucket,
> and then look at the **timestamp** of the change on BitBucket.
> How does BitBucket record times, and why?
> push those changes to Bitbucket,
> and then look at the **timestamp** of the change on Bitbucket.
> How does Bitbucket record times, and why?
2 changes: 1 addition & 1 deletion 04-open.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ but requires more time and effort to set up than either
the option above or the option below.

The third option is to use a public hosting service like [GitHub](http://github.com),
[BitBucket](http://bitbucket.org),
[Bitbucket](http://bitbucket.org),
[Google Code](http://code.google.com),
or [SourceForge](http://sourceforge.net).
All of these allow people to create repositories through a web interface,
Expand Down

0 comments on commit 2ec9924

Please sign in to comment.