164

I have a very small repo in which I do all dev work in the master branch and use tags as "stable" points in history.

I guess by default Bower seems to fetch the latest tagged version of a repo. I'm trying to get the most recent commit in the master branch.

I've tried running all these, in every conceivable order:

bower cache-clean mypackage
bower install mypackage --force-latest
bower install mypackage --force --force-latest
bower install mypackage --force

I've also tried adding latest to my bower.json file:

"dependencies": {
  "mypackage": "latest"
}

And then running:

bower update mypackage

No matter what it seems to always get the latest tagged state.

How do I get the latest, most up-to-date, untagged state of the project?

John
  • 3,866
  • 6
  • 33
  • 37

6 Answers6

220

Specify a git commit SHA instead of a version:

bower install '<git-url>#<git-commit-sha>'

Example:

bower install 'git://github.com/yeoman/stringify-object.git#d2895fb97d'

You can also specify a branch instead of a SHA, but that's generally not recommended unless it's in development and you control all the parts.

Sindre Sorhus
  • 62,972
  • 39
  • 168
  • 232
  • 1
    Ya, I read through all the discussion about all that in the GH issue tracker last night and installed bower#0.9.3-rc0. You are correct sir. Thanks! – John Jun 06 '13 at 16:20
  • 32
    By now, you can also just use `#` instead of adding a SHA-ID. So you can also use `#master` to track the master branch. – MKroehnert Nov 02 '13 at 08:44
  • 3
    This doesn't seem to work for my private repository though. I am trying to specify the commit id. It returns an error " fatal: reference is not a tree:". Looks like it's trying to find the revision in container's git repo. – Nilesh Apr 16 '14 at 00:54
  • 1
    I'm getting the fatal: reference is not a tree as well. Quite annoying. – Seiyria Feb 25 '15 at 04:47
  • how do you force the install of an older version in the package.json if you already have a newer one? – SuperUberDuper Mar 26 '15 at 12:26
112

Yes, you can point to the git url, or use name/repo shorthand (for github repos):

bower.json

{
  "name": "bower-test",
  "dependencies": {
    "dpm": "git@github.com:okfn/dpm.git",
    "docker-nmpjs": "terinjokes/docker-npmjs"
  }
}

More in the docs

As @roi noted in the comments, you can use the --save flag to automatically add dependencies to bower.json, e.g. bower install terinjokes/docker-npmjs --save

Roman Pushkin
  • 5,639
  • 3
  • 40
  • 58
Nick Tomlin
  • 28,402
  • 11
  • 61
  • 90
  • 1
    and is selecting a version possible? – Tjorriemorrie Mar 22 '14 at 07:44
  • 12
    @Tjorriemorrie Yes, you can follow the ``#.`` format listed in the docs. So, to use the latest version of jQuery in the "master" branch, you would do: ``git@github.com:jquery/jquery.git#master`` or ``jquery/jquery#master`` for short. – Nick Tomlin Mar 25 '14 at 19:04
  • 6
    i would say you'll have better luck using the cli to get it into your bower.json..... bower install terinjokes/docker-npmjs --save – Roi Apr 19 '14 at 20:09
  • 1
    We can also mention the releases / tags using # symbol like so - `xyz-components": "git@github.sample.com:username/reponame.git#0.4.5` – Nitin Jun 26 '15 at 18:57
32

You can install a branch in Bower > 1.0.0:

bower install xxx#foo-branch

More details at https://github.com/bower/bower/issues/107#issuecomment-22352689.

Giovanni Cappellotto
  • 4,597
  • 1
  • 30
  • 33
17

If you are using a bower.json file you specify the latest version of a branch with a line in either the dependencies or devDependencies as appropriate for your project configuration:

"angular-bootstrap": "git@github.com:angular-ui/bootstrap.git#bootstrap3",

Then when you run bower install the latest version of that branch is installed. That would be branch bootstrap3 of angular-ui in this example.

wibobm
  • 696
  • 7
  • 13
15
bower install --save package-name#master

adds this:

"dependencies": {
  "package-name": "master"
}
elado
  • 8,510
  • 9
  • 51
  • 60
10

using bower.json:

"dependencies": {
    "jquery.slimscroll": "latest",
    "jQuery": "1.11",
    "fullPage.js": "git@github.com:overbyte/fullPage.js.git#1d6bbac3d4c3b1d3d7d4096cdbcabd1c3914393f",
}

where

"[library name - in this case a forked version of fullpage.js]" : "[from git clone box in github][#commit number if required - without this you will get latest tagged version]"
obie
  • 578
  • 7
  • 23