In your local clone of your forked repository, you can add the original GitHub repository as a "remote". ("Remotes" are like nicknames for the URLs of repositories - origin
is one, for example.) Then you can fetch all the branches from that upstream repository, and rebase your work to continue working on the upstream version. In terms of commands that might look like:
# Add the remote, call it "upstream":
git remote add upstream https://github.com/whoever/whatever.git
# Fetch all the branches of that remote into remote-tracking branches
git fetch upstream
# Make sure that you're on your master branch:
git checkout master
# Rewrite your master branch so that any commits of yours that
# aren't already in upstream/master are replayed on top of that
# other branch:
git rebase upstream/master
If you don't want to rewrite the history of your master branch, (for example because other people may have cloned it) then you should replace the last command with git merge upstream/master
. However, for making further pull requests that are as clean as possible, it's probably better to rebase.
If you've rebased your branch onto upstream/master
you may need to force the push in order to push it to your own forked repository on GitHub. You'd do that with:
git push -f origin master
You only need to use the -f
the first time after you've rebased.
Update 30th, January 2013, 16 months later:
Starting today, GitHub supports relative links in markup files.
Now you can link directly between different documentation files, whether you view the documentation on GitHub itself, or locally, using a different markup renderer.
You want examples of link definitions and how they work? Here's some Markdown for you.
Instead of an absolute link:
[a link](https://github.com/user/repo/blob/branch/other_file.md)
…you can use a relative link:
[a relative link](other_file.md)
[a relative link](path%20with%20spaces/other_file.md)
and we'll make sure it gets linked to user/repo/blob/branch/other_file.md
.
If you were using a workaround like [a workaround link](repo/blob/master/other_file.md)
, you'll have to update your documentation to use the new syntax.
This also means your documentation can now easily stand on its own, without always pointing to GitHub.
Marcono1234 adds in the comments
Also useful: When the link starts with a /
, it is relative to the root of the repository (regardless of whether the markdown file is nested in subdirectories)
Update December 20th, 2011:
The GitHub markup issue 84 is currently closed by technoweenie, with the comment:
We tried adding a <base>
tag for this, but it causes problems with other relative links on the site.
October 12th, 2011:
If you look at the raw source of the README.md
of Markdown itself(!), relative paths don't seem to be supported.
You will find references like:
[r2h]: http://github.com/github/markup/tree/master/lib/github/commands/rest2html
[r2hc]: http://github.com/github/markup/tree/master/lib/github/markups.rb#L13
As noted in InvisibleWolf's answer, if the target link is a directory and it has space, then you need to use %20
for each space.
Best Answer
It is nicely demonstrated in the Table of Contents of the Markdown Cheatsheet.
If you hover over a Header in a GitHub Markdown file, you'll see a little link simple to the left of it, you can also use that link. The format for that link is
<project URL#<header name>
. The<header name>
must be all lower case.