Rectangle 27 8

This solution allows you to use true HTTP redirects via .htaccess how...

<meta>

I don't like the <meta> approach so I whipped up a solution for anyone looking to provide real HTTP 301 redirects within an .htaccess file using Apache, which serves a pre-generated Jekyll site:

.htaccess
include
_config.yml
include: [.htaccess]

Next, create an .htaccess file and be sure to include YAML front matter. Those dashes are important because now Jekyll will parse the file with Liquid, Jekyll's templating language:

---
---
DirectoryIndex index.html

RewriteEngine On
RewriteBase /

...

Make sure your posts that require redirects have two properties like so:

---
permalink: /my-new-path/
original: blog/my/old/path.php
---

Now in .htaccess, just add a loop:

{% for post in site.categories.post %}
  RewriteRule ^{{ post.original }} {{ post.permalink }} [R=301,L]
{% endfor %}

This will dynamically generate .htaccess every time you build the site, and the include in your config file ensures that .htaccess makes it into _site directory.

RewriteRule ^blog/my/old/path.php /my-new-path/ [R=301,L]

From there, it's up to you to serve _site using Apache. I normally clone the full Jekyll repo into a non-webroot directory, then my vhost is a symlink to the _site folder:

ln -s /path/to/my-blog/_site /var/www/vhosts/my-blog.com

Tada! Now Apache can serve the _site folder from your virtual root, complete with .htaccess-powered redirects that use whichever HTTP response code you desire!

You could even get super fancy and use a redirect property within each post's front matter to designate which redirect code to use in your .htaccess loop.

This seems great! But what if there are multiple original(previous links now hitting 404) links for a post?

The solution would involve a more complex piece of logic when you generate the .htaccess file. For example, you could convert the YAML so that original is an array instead of a string. Then you need a nested loop so that every original entry generates a redirect to permalink. Take this code as a starting point and experiment for yourself!

Thank you. I got it to work as you suggested. I've used this method for a tutorial.

redirect - What is the best approach for redirection of old pages in J...

redirect github jekyll http-status-code-301 github-pages
Rectangle 27 8

This solution allows you to use true HTTP redirects via .htaccess how...

<meta>

I don't like the <meta> approach so I whipped up a solution for anyone looking to provide real HTTP 301 redirects within an .htaccess file using Apache, which serves a pre-generated Jekyll site:

.htaccess
include
_config.yml
include: [.htaccess]

Next, create an .htaccess file and be sure to include YAML front matter. Those dashes are important because now Jekyll will parse the file with Liquid, Jekyll's templating language:

---
---
DirectoryIndex index.html

RewriteEngine On
RewriteBase /

...

Make sure your posts that require redirects have two properties like so:

---
permalink: /my-new-path/
original: blog/my/old/path.php
---

Now in .htaccess, just add a loop:

{% for post in site.categories.post %}
  RewriteRule ^{{ post.original }} {{ post.permalink }} [R=301,L]
{% endfor %}

This will dynamically generate .htaccess every time you build the site, and the include in your config file ensures that .htaccess makes it into _site directory.

RewriteRule ^blog/my/old/path.php /my-new-path/ [R=301,L]

From there, it's up to you to serve _site using Apache. I normally clone the full Jekyll repo into a non-webroot directory, then my vhost is a symlink to the _site folder:

ln -s /path/to/my-blog/_site /var/www/vhosts/my-blog.com

Tada! Now Apache can serve the _site folder from your virtual root, complete with .htaccess-powered redirects that use whichever HTTP response code you desire!

You could even get super fancy and use a redirect property within each post's front matter to designate which redirect code to use in your .htaccess loop.

This seems great! But what if there are multiple original(previous links now hitting 404) links for a post?

The solution would involve a more complex piece of logic when you generate the .htaccess file. For example, you could convert the YAML so that original is an array instead of a string. Then you need a nested loop so that every original entry generates a redirect to permalink. Take this code as a starting point and experiment for yourself!

Thank you. I got it to work as you suggested. I've used this method for a tutorial.

redirect - What is the best approach for redirection of old pages in J...

redirect github jekyll http-status-code-301 github-pages
Rectangle 27 9

I need to wait now for google to re-index, but it should do it. According to this question and this google article a canonical link tag in the head should fix it.

<link rel="canonical" href="http://www.[website-url]"/>

I also added a js redirect trick to redirect the people coming from google.

if ( window.self === window.top ) { 
    // console.log("not in a frame") 
       window.location.href = 'http://www.[website-url]';
    }

html - How to make google index my custom domain instead of the github...

html github dns github-pages
Rectangle 27 9

I need to wait now for google to re-index, but it should do it. According to this question and this google article a canonical link tag in the head should fix it.

<link rel="canonical" href="http://www.[website-url]"/>

I also added a js redirect trick to redirect the people coming from google.

if ( window.self === window.top ) { 
    // console.log("not in a frame") 
       window.location.href = 'http://www.[website-url]';
    }

html - How to make google index my custom domain instead of the github...

html github dns github-pages
Rectangle 27 2

I also want to edit docs in master and publish in gh-pages - I like to keep the docs up to date with the source code and that seems like the best way. This is work in progress for me, but I took Cory's script as a starting point and expanded it a bit to make it work out of the box as long as there is a gh-pages branch with _layouts (i.e. a jekyll site). It converts backtick style fencing (for code blocks) which work nicely in github source browsing, but not in the gh-pages. I use an index.md with an include for the project README.md so I can add a header and some other decorations. This version also handles documentation in any nested directories called "docs" which I find useful in a project with multiple modules (not git submodules, just subdirectories):

.git/hooks/post-commit
#!/bin/bash
###
### The following block runs after commit to "master" branch
###
if [ `git rev-parse --abbrev-ref HEAD` == "master" ]; then

    # function to convert a plain .md file to one that renders nicely in gh-pages
    function convert {
        # sed - convert links with *.md to *.html (assumed relative links in local pages)
        # awk - convert backtick fencing to highlights (script from bottom of file)
        sed -e 's/(\(.*\)\.md)/(\1.html)/g' "$1" | awk -f <(sed -e '0,/^#!.*awk/d' $0) > _temp && mv _temp "$1"
    } 

    if ! git show-ref --verify --quiet refs/heads/gh-pages; then
        echo "No gh-pages, so not syncing"
        exit 0
    fi

    # Switch to gh-pages branch to sync it with master
    ###################################################################
    git checkout gh-pages

    mkdir -p _includes

    # Sync the README.md in master to index.md adding jekyll header
    ###################################################################
    git checkout master -- README.md
    if [ -f README.md ]; then
        cp README.md _includes/
        convert _includes/README.md
        git add README.md
        git add _includes/README.md
    fi

    # Generate index if there isn't one already
    ###################################################################
    if [ ! -f index.md ]; then
        echo -e '---\ntitle: Docs\nlayout: default\n---\n\n{% include README.md %}' > index.md
        git add index.md
    fi

    # Generate a header if there isn't one already
    ###################################################################
    if [ ! -f _includes/header.txt ]; then
        echo -e '---\ntitle: Docs\nlayout: default\nhome: \n---\n\n' > _includes/header.txt
        git add _includes/header.txt
    fi

    # Sync the markdown files in all docs/* directories
    ###################################################################
    for file in `git ls-tree -r --name-only master | grep 'docs/.*\.md'`
    do
        git checkout master -- "$file"
        dir=`echo ${file%/*} | sed -e "s,[^/]*,..,g"`
        cat _includes/header.txt | sed -e "s,^home: .*$,home: ${dir}/," > _temp
        cat "$file" >> _temp && mv _temp "$file"
        convert "$file"
        git add "$file"
    done

    git commit -a -m "Sync docs from master branch to docs gh-pages directory"

    # Uncomment the following push if you want to auto push to
    # the gh-pages branch whenever you commit to master locally.
    # This is a little extreme. Use with care!
    ###################################################################
    # git push origin gh-pages

    # Finally, switch back to the master branch and exit block
    git checkout master
fi

exit $?

#!/usr/bin/awk
{
   # Replace backtick fencing (renders well when browsing github) with jekyll directives
   if (/```/) {
      IN = IN?0:1 # Are we already in a fenced section? Toggle.
      if (IN) { # If we are starting a fenced section
         if (/```\s*$/) {
           $0 = $0"text" # empty language is OK for backticks but not for jekyll
         }
         gsub(/```/, "{% highlight ")
         print $0" %}"
      } else { # ending a fenced section
        print "{% endhighlight %}" 
      }
    } else { # not a fencing line
      if (IN) { # but in a fenced section, so add indent to make sure code is rendered with <pre>
        print "    "$0
      } else {
        print
      }
    }
}

Another variation from the original is that it sets a variable page.home in all pages. This can be used to locate the relative path of the root diractory, so it can be used to locate static resources like css. In _layouts/.default.html I have:

<link rel="stylesheet" href="{{ page.home }}css/main.css">

In that way I can edit the css, build the jekyll site locally, and see the result in a browser without having to wait for github to build it on the server.

git - How can I sync documentation with Github Pages? - Stack Overflow

git github github-pages webhooks
Rectangle 27 2

I also want to edit docs in master and publish in gh-pages - I like to keep the docs up to date with the source code and that seems like the best way. This is work in progress for me, but I took Cory's script as a starting point and expanded it a bit to make it work out of the box as long as there is a gh-pages branch with _layouts (i.e. a jekyll site). It converts backtick style fencing (for code blocks) which work nicely in github source browsing, but not in the gh-pages. I use an index.md with an include for the project README.md so I can add a header and some other decorations. This version also handles documentation in any nested directories called "docs" which I find useful in a project with multiple modules (not git submodules, just subdirectories):

.git/hooks/post-commit
#!/bin/bash
###
### The following block runs after commit to "master" branch
###
if [ `git rev-parse --abbrev-ref HEAD` == "master" ]; then

    # function to convert a plain .md file to one that renders nicely in gh-pages
    function convert {
        # sed - convert links with *.md to *.html (assumed relative links in local pages)
        # awk - convert backtick fencing to highlights (script from bottom of file)
        sed -e 's/(\(.*\)\.md)/(\1.html)/g' "$1" | awk -f <(sed -e '0,/^#!.*awk/d' $0) > _temp && mv _temp "$1"
    } 

    if ! git show-ref --verify --quiet refs/heads/gh-pages; then
        echo "No gh-pages, so not syncing"
        exit 0
    fi

    # Switch to gh-pages branch to sync it with master
    ###################################################################
    git checkout gh-pages

    mkdir -p _includes

    # Sync the README.md in master to index.md adding jekyll header
    ###################################################################
    git checkout master -- README.md
    if [ -f README.md ]; then
        cp README.md _includes/
        convert _includes/README.md
        git add README.md
        git add _includes/README.md
    fi

    # Generate index if there isn't one already
    ###################################################################
    if [ ! -f index.md ]; then
        echo -e '---\ntitle: Docs\nlayout: default\n---\n\n{% include README.md %}' > index.md
        git add index.md
    fi

    # Generate a header if there isn't one already
    ###################################################################
    if [ ! -f _includes/header.txt ]; then
        echo -e '---\ntitle: Docs\nlayout: default\nhome: \n---\n\n' > _includes/header.txt
        git add _includes/header.txt
    fi

    # Sync the markdown files in all docs/* directories
    ###################################################################
    for file in `git ls-tree -r --name-only master | grep 'docs/.*\.md'`
    do
        git checkout master -- "$file"
        dir=`echo ${file%/*} | sed -e "s,[^/]*,..,g"`
        cat _includes/header.txt | sed -e "s,^home: .*$,home: ${dir}/," > _temp
        cat "$file" >> _temp && mv _temp "$file"
        convert "$file"
        git add "$file"
    done

    git commit -a -m "Sync docs from master branch to docs gh-pages directory"

    # Uncomment the following push if you want to auto push to
    # the gh-pages branch whenever you commit to master locally.
    # This is a little extreme. Use with care!
    ###################################################################
    # git push origin gh-pages

    # Finally, switch back to the master branch and exit block
    git checkout master
fi

exit $?

#!/usr/bin/awk
{
   # Replace backtick fencing (renders well when browsing github) with jekyll directives
   if (/```/) {
      IN = IN?0:1 # Are we already in a fenced section? Toggle.
      if (IN) { # If we are starting a fenced section
         if (/```\s*$/) {
           $0 = $0"text" # empty language is OK for backticks but not for jekyll
         }
         gsub(/```/, "{% highlight ")
         print $0" %}"
      } else { # ending a fenced section
        print "{% endhighlight %}" 
      }
    } else { # not a fencing line
      if (IN) { # but in a fenced section, so add indent to make sure code is rendered with <pre>
        print "    "$0
      } else {
        print
      }
    }
}

Another variation from the original is that it sets a variable page.home in all pages. This can be used to locate the relative path of the root diractory, so it can be used to locate static resources like css. In _layouts/.default.html I have:

<link rel="stylesheet" href="{{ page.home }}css/main.css">

In that way I can edit the css, build the jekyll site locally, and see the result in a browser without having to wait for github to build it on the server.

git - How can I sync documentation with Github Pages? - Stack Overflow

git github github-pages webhooks
Rectangle 27 265

HTTP interceptors aren't supported in Angular 2 but there is an interesting discussion on this subject in the Angular Github: https://github.com/angular/angular/issues/2684.

To answer, you question you could provide a service that wraps the original Http object from Angular2. Something like described below.

import {Injectable} from '@angular/core';
import {Http, Headers} from '@angular/http';

@Injectable()
export class HttpClient {

  constructor(private http: Http) {}

  createAuthorizationHeader(headers: Headers) {
    headers.append('Authorization', 'Basic ' +
      btoa('username:password')); 
  }

  get(url) {
    let headers = new Headers();
    this.createAuthorizationHeader(headers);
    return this.http.get(url, {
      headers: headers
    });
  }

  post(url, data) {
    let headers = new Headers();
    this.createAuthorizationHeader(headers);
    return this.http.post(url, data, {
      headers: headers
    });
  }
}

And instead of injecting the Http object you could inject this one (HttpClient).

import { HttpClient } from './http-client';

export class MyComponent {
  // Notice we inject "our" HttpClient here, naming it Http so it's easier
  constructor(http: HttpClient) {
    this.http = httpClient;
  }

  handleSomething() {
    this.http.post(url, data).subscribe(result => {
        // console.log( result );
    });
  }
}

I also think that something could be done using multi providers for the Http class by providing your own class extending the Http one... See this link: http://blog.thoughtram.io/angular2/2015/11/23/multi-providers-in-angular-2.html.

Can you provide this answer for angular 2 final version, I try to replicate this but I'm getting a bunch of errors when I try to use the extended method?

where is 'this.http = http;' comes from , I believe we need to declare it before using ?

angular Headers (set & append functions) is "normalizing" the header's key and makes it lower-case. From Headers.d.ts: // "HTTP character sets are identified by case-insensitive tokens" // Spec at tools.ietf.org/html/rfc2616 For those who doesn't have a backend that works by the spec; here's a bypass: let headersMap = .get(options, 'headers._headersMap', new Map()); headersMap.set('Authorization', [.replace(Bearer ${token}, /\"/g, '')]);

@DiegoUnanue @Kalanamith Everything is updated to the latest just now. I also removed the unneccesary this.http=http and just instantiated it in the constructor with private http: Http instead. Hope that helps!

angular - Angular2 - set headers for every request - Stack Overflow

angular typescript http-headers
Rectangle 27 6

You could use github pages and here is how to do it: http://pages.github.com/

Pull the branch gh-pages, modify as you like, commit and push.

repository - How to do web hosting using github - Stack Overflow

github repository
Rectangle 27 6

You could use github pages and here is how to do it: http://pages.github.com/

Pull the branch gh-pages, modify as you like, commit and push.

repository - How to do web hosting using github - Stack Overflow

github repository
Rectangle 27 6

You could use github pages and here is how to do it: http://pages.github.com/

Pull the branch gh-pages, modify as you like, commit and push.

repository - How to do web hosting using github - Stack Overflow

github repository
Rectangle 27 6

You could use github pages and here is how to do it: http://pages.github.com/

Pull the branch gh-pages, modify as you like, commit and push.

repository - How to do web hosting using github - Stack Overflow

github repository
Rectangle 27 18

If you created the token you're using through the Applications page, then this token will have these scopes: user, public_repo, repo, gist. You can verify this by making an API request with that token and looking at the response HTTP headers:

curl -v -H 'Authorization: token xxx' https://api.github.com

Look for the X-OAuth-Scopes response header which will have the list of scopes:

X-OAuth-Scopes: user, public_repo, repo, gist

So, you need a token that has different scopes than the one you have. You can create such a token using the Authorizations API:

curl -v -u username -X POST https://api.github.com/authorizations -d '{"scopes":["delete_repo"], "note":"token with delete repo scope"}'

This will return a JSON document with the new token which you should be able to use to delete a repository:

{
  "id": XXXXX,
  "url": "https://api.github.com/authorizations/XXXXX",
  "app": {
    "name": "GitHub API",
    "url": "http://developer.github.com/v3/oauth/#oauth-authorizations-api",
    "client_id": "00000000000000000000"
  },
  "token": "XXXXXX",
  "note": "token with delete repo scope",
  "note_url": null,
  "created_at": "2013-10-11T20:34:49Z",
  "updated_at": "2013-10-11T20:34:49Z",
  "scopes": [
    "delete_repo"
  ]
}

Of course, when creating a token this way, you can ask for multiple scopes, not just the delete_repo scope.

Also, as a side-note, the reason why the API is returning a 404 error when you don't have the right authorization is to prevent information leakage.

The Github website user interface now provides a means of creating a token with multiple scopes. If @Ivan Zuzak could please update his answer to include a current example of how to create a multiple scope tokken from the command line, that would be greatly appreciated. My attempts at using curl -v -u username -X POST https://api.github.com/authorizations -d '{"scopes":["delete_repo"]}' did not work -- perhaps because the API has changed since the original post.

... /:owner/:repo
delete_repo
curl -X DELETE -H 'Authorization: token xxx' https://api.github.com/repos/USERNAME/NAME-OF-REPO

@lawlist You were probably getting a warning that you didn't supply a "note", which is a required field as of recently: developer.github.com/v3/oauth_authorizations/. I updated the example to include a note. Let me know if you're still having trouble and please provide the error you're getting from the API.

Also, those colons are a standard way of describing parameters in the path part of an URL: developer.github.com/v3/#parameters

How to delete a GitHub repo using the API - Stack Overflow

github-api
Rectangle 27 58

http://prose.io is a great tool! It's hosted on github pages and is a database-less app that works totally through the github API. Has some neat features for editor experience if you happen to have a GitHub Jekyll website as well.

Wow, yeah, I guess, but you're trusting your whole codebase to a third party.

@artfulrobot well if it's an open source project then that doesn't change much.

git - What's the best way to edit GitHub's Readme.md? - Stack Overflow

git documentation github
Rectangle 27 57

http://prose.io is a great tool! It's hosted on github pages and is a database-less app that works totally through the github API. Has some neat features for editor experience if you happen to have a GitHub Jekyll website as well.

Wow, yeah, I guess, but you're trusting your whole codebase to a third party.

@artfulrobot well if it's an open source project then that doesn't change much.

git - What's the best way to edit GitHub's Readme.md? - Stack Overflow

git documentation github
Rectangle 27 56

http://prose.io is a great tool! It's hosted on github pages and is a database-less app that works totally through the github API. Has some neat features for editor experience if you happen to have a GitHub Jekyll website as well.

Wow, yeah, I guess, but you're trusting your whole codebase to a third party.

@artfulrobot well if it's an open source project then that doesn't change much.

git - What's the best way to edit GitHub's Readme.md? - Stack Overflow

git documentation github
Rectangle 27 56

http://prose.io is a great tool! It's hosted on github pages and is a database-less app that works totally through the github API. Has some neat features for editor experience if you happen to have a GitHub Jekyll website as well.

Wow, yeah, I guess, but you're trusting your whole codebase to a third party.

@artfulrobot well if it's an open source project then that doesn't change much.

git - What's the best way to edit GitHub's Readme.md? - Stack Overflow

git documentation github
Rectangle 27 90

Here are some examples of HTTP API Rate Limiting HTTP Response headers. Taken from four common REST APIs: Github, Vimeo, Twitter and Imgur:

Note: Twitter uses headers with similar names like Vimeo, but has another dash in each name.

#=============================#=============================================#
# HTTP Header                 # Description                                 #
#=============================#=============================================#
| X-Rate-Limit-Limit          | The rate limit ceiling for that given       |
|                             | request                                     |
+-----------------------------+---------------------------------------------+
| X-Rate-Limit-Remaining      | The number of requests left for the         |
|                             | 15 minute window                            |
+-----------------------------+---------------------------------------------+
| X-Rate-Limit-Reset          | The remaining window before the rate limit  |
|                             | resets in UTC epoch seconds                 |
+-----------------------------+---------------------------------------------+
#=============================#=============================================#
# HTTP Header                 # Description                                 #
#=============================#=============================================#
| X-RateLimit-UserLimit       | Total credits that can be allocated         |
+-----------------------------+---------------------------------------------+
| X-RateLimit-UserRemaining   | Total credits available                     |
+-----------------------------+---------------------------------------------+
| X-RateLimit-UserReset       | Timestamp (unix epoch) for when the credits |
|                             | will be reset                               |
+-----------------------------+---------------------------------------------+
| X-RateLimit-ClientLimit     | Total credits that can be allocated for the |
|                             | application in a day                        |
+-----------------------------+---------------------------------------------+
| X-RateLimit-ClientRemaining | Total credits remaining for the application |
|                             | in a day                                    |
+-----------------------------+---------------------------------------------+

If you're designing your own rate-limit headers, the Best Current Practice BCP178 is a relevant resource, recommending that the X- prefix be deprecated. Check out the original RFC/BCP for more info. tools.ietf.org/html/bcp178

Great examples, I made a Node.js package that can be used with the request package: github.com/webjay/x-rate

Examples of HTTP API Rate Limiting HTTP Response headers - Stack Overf...

api http rest rate-limiting
Rectangle 27 53

<meta http-equiv="refresh"
<link rel="canonical" href=

It works very well, Google Bot reindexed my entire website under new links without losing positions. Also the users are redirected to the new posts right away.

<meta http-equiv="refresh" content="0; url=http://konradpodgorski.com/blog/2013/10/21/how-i-migrated-my-blog-from-wordpress-to-octopress/">
<link rel="canonical" href="http://konradpodgorski.com/blog/2013/10/21/how-i-migrated-my-blog-from-wordpress-to-octopress/" />

Using <meta http-equiv="refresh" will redirect each visitor to the new post. As for Google Bot, it treats <link rel="canonical" href= as 301 redirect, the effect is that you get your pages reindexed and that is what you want.

Does the effect of using canonical imply that Google will reindex the pages from scratch, or does it transfer the ranking score to the new page? Can you clarify how this approach affects the page ranking?

Won't the <meta http-equiv="refresh" cause an infinite redirect loop? That is what I am getting, maybe I am doing something wrong?

@ErikBerkun-Drevnig the content seen above is added on the "old" page and should point to the "new" page. Done that way, there should not be an infinite loop.

redirect - What is the best approach for redirection of old pages in J...

redirect github jekyll http-status-code-301 github-pages
Rectangle 27 53

<meta http-equiv="refresh"
<link rel="canonical" href=

It works very well, Google Bot reindexed my entire website under new links without losing positions. Also the users are redirected to the new posts right away.

<meta http-equiv="refresh" content="0; url=http://konradpodgorski.com/blog/2013/10/21/how-i-migrated-my-blog-from-wordpress-to-octopress/">
<link rel="canonical" href="http://konradpodgorski.com/blog/2013/10/21/how-i-migrated-my-blog-from-wordpress-to-octopress/" />

Using <meta http-equiv="refresh" will redirect each visitor to the new post. As for Google Bot, it treats <link rel="canonical" href= as 301 redirect, the effect is that you get your pages reindexed and that is what you want.

Does the effect of using canonical imply that Google will reindex the pages from scratch, or does it transfer the ranking score to the new page? Can you clarify how this approach affects the page ranking?

Won't the <meta http-equiv="refresh" cause an infinite redirect loop? That is what I am getting, maybe I am doing something wrong?

@ErikBerkun-Drevnig the content seen above is added on the "old" page and should point to the "new" page. Done that way, there should not be an infinite loop.

redirect - What is the best approach for redirection of old pages in J...

redirect github jekyll http-status-code-301 github-pages
Rectangle 27 43

The only way to do this would be to pass the link through my own service which would use the github's http referrer header to determine which branch is being referenced and then fetch the appropriate image from Travis CI

I would rather make one Travis-CI badge per branch, for the reader to choose or consider the appropriate when seeing the README.md.

Update 2016 (3 years later): while nothing has changed on the GitHub side, fedorqui reports in the workaround mentioned in "Get Travis Shield on Github to Reflect Selected Branch Status" by Andrie. Simply display all the branches and their respective TravisCI badges.

If you have only two or three branches, that could be enough.

Thanks, VonC. I contacted github support, as you suggested and here's their reply:

They confirmed that this can't be done. They said the only way to do this would be to pass the link through my own service which would use the github's http referrer header to determine which branch is being referenced and then fetch the appropriate image from Travis CI...

I just tried to pass the link through my own service but unfortunately I dont get the HTTP_REFERER when the image is loaded from the README on GitHub. :-(

@fedorqui As far as I know, it is not available.

markdown - Referencing current branch in github readme.md - Stack Over...

github markdown travis-ci