I need to have a relative link to root of my repo from markdown file
(I need it working for any forks)
So it looks like the only way it's to provide a link to some file in the root:
the [Root](/README.md)
or
the [Root](../README.md)
(if it's located at /doc/README.md for instance)
At the same time I can refer to any folder without referring to a file
the [Doc](/doc)
But if I try to put a link to the root folder:
the [real root](/)
the [real root](../)
I'll have a link such
https://github.com/UserName/RepoName/blob/master
which unlike the
https://github.com/UserName/RepoName/blob/master/doc
refers to 404
So if I don't want to refer to README.md in the root (I could havn't it at all)
Is there any way to have such a link?
After some research I've found this solution:
[the real relative root of any fork](/../../)
It always points to the default branch. For me it's Ok, so it's up to you
PS
With such a trick you can also access the following abilities:
[test](/../../tree/test) - link to another branch
[doc/readme.md](/../../edit/master/doc/readme.md) - open in editor
[doc/readme.md](/../../delete/master/doc/readme.md) - ask to delete file
[doc/readme.md](/../../commits/master/doc/readme.md) - history
[doc/readme.md](/../../blame/master/doc/readme.md) - blame mode
[doc/readme.md](/../../raw/master/doc/readme.md) - raw mode (will redirect)
[doc/](/../../new/master/doc/) - ask to create new file
[doc/](/../../upload/master/doc/) - ask to upload file
[find](/../../find/test) - find file
You can either link directly to the file (../README.md), or simply use a full absolute URL to link directly to the repo root: https://github.com/UserName/RepoName
Using relative links doesn't work so well on GitHub. Notice the difference between the following two URLs:
https://github.com/UserName/RepoName/tree/master/somedir
https://github.com/UserName/RepoName/blob/master/somedir/somefile
Notice that the first points to a directory and the second points to a file. Yet, after the "RepoName" we have either one of tree (for a directory) or blob for a file. Therefore relative links between the two won't work properly. On GitHub, you can't use relative links to link between a file and a directory. However, you can link between two files (as both URLs contain blob). Therefore, if you wanted to link from somefile back to README.md in the root, you could do:
[README](../README.md)
That would give you the URL:
https://github.com/UserName/RepoName/blob/master/somedir/../README.md
which would get normalized to
https://github.com/UserName/RepoName/blob/master/README.md
However, if you just want to point to the root of your Repo (or any other dir), then it is probably best to use a full URL. After all, if someone has downloaded your repo and is viewing the source locally, the relative URL to the Repo root will be different than when viewing the file on GitHub. In that case, you probably want to point them to GitHub anyway. Therefore, you should use:
[root](https://github.com/UserName/RepoName)
Another advantage of that is that if your documentation ever gets published elsewhere (perhaps a documentation hosting service), the link will still point to the GitHub repo, not some random page on the hosting service. After all, the README at your project root is not likely to get included with the contents of the docs/ dir on said hosting service.
Perhaps it would help to understand how GitHub's URL scheme presumably works. I say "presumably" as I have no inside knowledge, just a general understanding of how these types of systems are generally designed.
GitHub is not serving flat files. Rather their server is taking the URL apart, and uses the various pieces to return the proper response. The URL structure looks something like this:
https://github.com/<username>/<repository name>/<resource type>/<branch>/<resource path>
The username, repository name, resource type, and branch are rather arbitrary and just ways to GitHub to ensure they are pulling information from the correct location.
The resource type matters as they are likely not pulling files from a working tree. Rather they are pulling the files/directory listings directly from the Repo itself through a lower level. In that case, obtaining a file is very different than obtaining a directory listing and requires a different code path. Therefore, you can't request a blob (file) with aresource path that points to a tree (directory) or visa versa. The server gets confused and returns an error.
The point is that GitHub's server works on a slightly different set of rules. You can use relative URLs to move around within the resource path part of the URL, but once you change the resource type in the resource path part of the URL, then GitHub's entire scheme is broken if you don't also change the resource type in the URL. However, browsers (or HTML or Markdown) have no knowledge about that and relative URLs don't compensate for that. Therefore, you can't reliably use relative URLs to move around within a GitHub repo unless you understand all of the subtleties. Sometimes its just better to use absolute links.
I'm attempting to create a short script to cache a dynamically generated web page on another server.
I only want the one page so using
wget http://domain/file
Could be enough but the file contains relative links, which arent valid on the host.
Any ideas of an easy way to replace the relative links with absolute ones pointing to the original server/domain?
You are looking for the -k option:
Downloaded files will be changed to refer to the file they point to as a relative link.
Not downloaded files will be changed to include host name and absolute path of the location they point to.
I am trying to create links in my README.md that link to example code using a relative path, as opposed to the absolute path I am using now. For example, in the markdown file, if I use this:
[someLabel](https://github.com/username/repoName/somePathTo/myExampleCode)
It works no problem. But I would like to link it up using something like this:
[someLabel](username/repoName/somePathTo/myExampleCode)
This does not link up, as it gives me the ol' 404 not found error. Is there a way to link my examples on Github to my README using a relative path?
They seem to have changed this since Aug 8 '12, so now all I had to do to reference my pdf file inside the Documentation folder (which is in my project's root) is this:
[file.pdf](Documentation/file.pdf)
So, no need to add blog/master part anymore. Hope it helps new people browsing this question.
Try leaving off the username/ part. A relative link to repoName/blob/master/whatever on a page at /username/repoName should take you to /username/repoName/blob/master/whatever, which is what you want, I think.
Here is a nuance. A leading slash changes the meaning of a link.
[someLabel](/repository/relative/link.txt)
[someLabel](directory/relative/link.txt)
I recently found out that the way you can use relative path in README.md is:
[file.pdf](/Documentation/file.pdf)
where Documentation is a folder at the root of my repository
I have search in google about your question and found your question and after reading all answers, I found another way we can add relative path in README.md file by this way,
[someLabel](./somePathTo/myExampleCode)
Add the leading ./ character when the path is pointing to a parent folder.
It will not give '404 not found error' in Github.
Is there a way to create a URL anchor, <a>, link from within a Markdown file, to another file within the same repository and branch (aka a link relative to the current branch)?
For example, in the master branch I have a README.md file, which I would like do something like:
# My Project
is really really cool. My Project has a subdir named myLib, see below.
## myLib documentation
see documentation [here](myLib/README.md)
This would allow me to link from one .md to another within the same branch and not have to worry about which branch I'm in (avoid having to do an absolute URL that includes the github.com branch name).
Here is a working example of what I mean:
GOTO http://github.com/rynop/testRel, link does not work.
GOTO http://github.com/rynop/testRel/blob/master/README.md, link works.
This is expected because at this point the starting URL is in the branch. Now how do I get it to pick up the current branch in the README.md at the root of the repository?
Update: I opened an issue against GitHub for this feature request.
Update 30th, January 2013, 16 months later:
GitHub Blog Post Relative links in markup files:
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.
For example, you have a repo like the following:
project/
text.md
subpro/
subtext.md
subsubpro/
subsubtext.md
subsubpro2/
subsubtext2.md
The relative link to subtext.md in text.md might look like this:
[this subtext](subpro/subtext.md)
The relative link to subsubtext.md in text.md might look like this:
[this subsubtext](subpro/subsubpro/subsubtext.md)
The relative link to subtext.md in subsubtext.md might look like this:
[this subtext](../subtext.md)
The relative link to subsubtext2.md in subsubtext.md might look like this:
[this subsubtext2](../subsubpro2/subsubtext2.md)
The relative link to text.md in subsubtext.md might look like this:
[this text](../../text.md)
GitHub could make this a lot better with minimal work. Here is a work-around.
I think you want something more like
[Your Title](your-project-name/tree/master/your-subfolder)
or to point to the README itself
[README](your-project-name/blob/master/your-subfolder/README.md)
As of January 31, 2013 Github markdown supports relative links to files.
[a relative link](markdown_file.md)
However, there are a few deficiencies that have been discussed in this comment thread.
As an alternative, you can use Gitdown to construct full URLs to the repository and even make them branch aware, e.g.
{"gitdown": "gitinfo", "name": "url"} // https://github.com/gajus/gitdown
{"gitdown": "gitinfo", "name": "branch"} // master
Gitdown is a GitHub markdown preprocessor. It streamlines common tasks associated with maintaining a documentation page for a GitHub repository, e.g. generating table of contents, including variables, generating URLs and getting information about the repository itself at the time of processing the input. Gitdown seamlessly integrates with your building scripts.
I am the author of the Gitdown library.
Just wanted to add this because none of the above solutions worked if target link is directory with spaces in it's name. If target link is a directory and it has space then even escaping space with \ doesn't render the link on Github. Only solution worked for me is using %20 for each space.
e.g.: if directory structure is this
Top_dir
|-----README.md
|-----Cur_dir1
|----Dir A
|----README.md
|----Dir B
|----README.md
To make link to Dir A in README.md present in Top_dir you can do this:
[Dir 1](Cur_dir1/Dir%20A)
You can link to file, but not to folders, and keep in mind that, Github will add /blob/master/ before your relative link(and folders lacks that part so they cannot be linked, neither with HTML <a> tags or Markdown link).
So, if we have a file in myrepo/src/Test.java, it will have a url like:
https://github.com/WesternGun/myrepo/blob/master/src/Test.java
And to link it in the readme file, we can use:
[This is a link](src/Test.java)
or: This is a link.
(I guess, master represents the master branch and it differs when the file is in another branch.)
You can use relative URLs from the root of your repo with <a href="">. Assuming your repo is named testRel, put the following in testRel/README.md:
# My Project
is really really cool. My Project has a subdir named myLib, see below.
## myLib docs
see documentation:
* myLib/
* myLib/README.md
This question is pretty old, but it still seems important, as it isn't easy to put relative references from readme.md to wiki pages on Github.
I played around a little bit and this relative link seems to work pretty well:
[Your wiki page](../../wiki/your-wiki-page)
The two ../ will remove /blob/master/ and use your base as a starting point. I haven't tried this on other repositories than Github, though (there may be compatibility issues).
In .md file when you want to create a link to any related files which is related to same project folder or URL based links:
Existing file link:
In .md file add showing name in [] box then open () in this box add / after that it will auto fetch all existing folders name form which you choose your folder then add '/' it will show inner file or 'folders`. This means it will auto fetch the paths and at the end, your URL is created.
Example:
[Enter Showing Name](/users/4000266/heysushil)
This line show like this:
Enter Showing Name
Add URLs on .md file
Follow the same process only change the () box path with URL like this:
[HeySushil - YouTube](https://youtube.com/heysushil)
This looks like HeySushil - YouTube
Note: Remember no need to add force manually after adding / on () box it will auto fetch all existing folders and files.
I am not sure if I see this option here. You can just create a /folder in your repository and use it directly:
[a relative link](/folder/myrelativefile.md)
No blob or tree or repository name is needed, and it works like a charm.
If you want a relative link to your wiki page on GitHub, use this:
Read here: [Some other wiki page](path/to/some-other-wiki-page)
If you want a link to a file in the repository, let us say, to reference some header file, and the wiki page is at the root of the wiki, use this:
Read here: [myheader.h](../tree/master/path/to/myheader.h)
The rationale for the last is to skip the "/wiki" path with "../", and go to the master branch in the repository tree without specifying the repository name, that may change in the future.
The behaviour in Github directory links in markdown files could create some headaches.
All files have an url are starting with blob,
blob/<branch>/<path>/<fileName>
whereas directories have an url starting with tree:
tree/<branch>/<path>
So no relative link to a directory should work. It points to an url that starts with a blob. Magically Github changes some relative path automatically to the tree path. Unfortunately not urls containing ".."
I investigate some time to examine the strange behaviour with Github directory links on https://github.com/fluentcodes/GitSamples-GIT/tree/github-readme-links.
Just follow the format below.
[TEXT TO SHOW](actual URL to navigate)
Here is what I found for relative links in github's .md files:
Relative links without ../ (aka. link to file in the same level, or in sub dir), seems always work.
Relative links that contains ../ works only when you are already in a page whose url contains substring /blob/.
Otherwise need to use full url that contains /blob/, to link.
Actually except top level /README.md, when view any other files, their url already contains /blob/.
Thus probably you can always use relative links that contains ../ in files, except /README.md.
But /README.md is in top level, thus it shouldn't need a relative link that contains ../.
So, you should never need a full path link (that contains github domain) to link to files in the same github repo.
Example (links among multiple language doc)
In /README.md, can use relative links without ../.
[中文](doc/cn/README.md) |
[日本語](doc/jp/README.md)
In /doc/cn/README.md, since when we view it, the url already contains /blob/, thus could use relative links with ../.
[English](../../README.md) |
[日本語](../jp/README.md)
(BTW, the example come from this git-merge-flow repo.)
What I found to work for relative folders:
[link text](subfolder/subsubfolder/relevantfolder/)
where relevant folder is the folder you are trying to link to. The backslash is needed after the folder name. I tried including the project name and tree/main in the path and the other things suggested in previous answers, that lead to a nonexistent page error. The subfolder is a folder within the overall repo project folder.
Thus, file links would be in the form of:
[link text](subfolder/subsubfolder/relevantfolder/index.html)
If the desired file is not in any folder or subfolder the link is simply:
[link text](README.md)
for example the README file is not in any subfolders, so that could be the exact relative link you use for the README file.
You can also insert your links (relative or absolute) at the bottom to reduce clutter in text.
It can also be a good option for repetitive links.
This is [my linked text].
[my linked text]: relative/path/in/repo/to/file.txt "Optional title for mouse hover"
This is my linked text.
I know questions related to Kal Calendar has been asked multiple times in Stackoverflow.
But i am stuck badly. Please share your views on this. So...
I have followed all instructions in https://github.com/klazuka/Kal but as soon as i run my app it says Kal.h no such file or directory error.
I think i am doing wrong in header search path. But i am adding relative path from my project's directory to the "Kal/src" directory.
On double click to header search path I check mark on recursive and then adding "/Volumes/Development/Imp/Astro 4Feb /klazuka-Kal-b2e164c/src" in the path field.
What's wrong in it ?
Please help
Look at their example. They use ../../src and I don't see $(SRCROOT) there, so I guess they are not pointing the header search path as they said in the readme file. You may just point the header path where you have placed their source (Kal/src) and make it relative your project. Hope this helps.
You didn't set root directory. Make it relative to your project.