When Git tells you it failed to push some refs

April 25, 2008 by Ed Spencer · 25 Comments 

I received an unhelpful error while trying to push to a repository on Github today:

git push
To git@github.com:user/repo.git
! [rejected] branchname -> branchname (non-fast forward)
error: failed to push some refs to 'git@github.com:user/repo.git'[/code]
In case you ever have the same problem, all you have to do is a quick git pull first, then you can carry on as normal. Easy when you know how...

Git clone vs Git submodule

April 17, 2008 by Ed Spencer · 8 Comments 

Having recently made the switch from svn to git, I wanted to achieve what svn externals did (and what Piston did better). Turns out this is pretty simple, for example to get rails on edge:

cd your_git_dir
git submodule add git://github.com/rails/rails.git vendor/rails[/code]
A couple of other default submodules you'll want:

git submodule add git://github.com/dchelimsky/rspec.git vendor\plugins\rspec
git submodule add git://github.com/dchelimsky/rspec-rails.git vendor\plugins\rspec-rails
[/code]
What submodule does is to check out the submodules as their own repositories, so they are tracked independently of the repository you made them submodules of. The submodules you have are tracked in the .gitmodules file, which might look something like this:

[submodule "vendor\rails"]
path = vendor/rails
url = git://github.com/rails/rails.git
[submodule "vendor/plugins/rspec"]
path = vendor/plugins/rspec
url = git://github.com/dchelimsky/rspec.git
[submodule "vendor/plugins/rspec-rails"]
path = vendor/plugins/rspec-rails
url = git://github.com/dchelimsky/rspec-rails.git
[/code]
Or at least that's how it should look, Windows seems to mess this up into looking something like the following:

[submodule "vendor\rails"]
path = vendor\\rails
[submodule "vendor\rails"]
url = git://github.com/rails/rails.git
[submodule "vendor\plugins\rspec"]
path = vendor\\plugins\\rspec
[submodule "vendor\plugins\rspec"]
url = git://github.com/dchelimsky/rspec.git
[submodule "vendor\plugins\rspec-rails"]
path = vendor\\plugins\\rspec-rails
[submodule "vendor\plugins\rspec-rails"]
url = git://github.com/dchelimsky/rspec-rails.git
[/code]
Note especially that you need to remove the \\'s and replace all \'s with /'s. If you don't git will give a fail message like:

fatal: bad config file line 2 in .gitmodules
No submodule mapping found in .gitmodules for path 'vendor/plugins/attachment_fu'
[/code]
I don't know why it's doing that, maybe it's something I'm doing wrong but you'll need to tidy it up to make it look more like the first example in order for it to work properly.

One final thing to be aware of is that when you clone onto a new machine you'll need to run the following commands:

git submodule init
git submodule update
[/code]
This will initialise the submodules that are referenced in the .gitmodules file, then pull them down. By default cloning doesn't seem to do that.