"updating paths is incompatible with switching branches/forcing" error when using git branches with Vlad
I ended up writing this snippet after I found out that deploying a git branch with vlad wasn’t as easy as it should’ve been…
I assumed the Vlad documentation was right, so I put the branch name in the revision variable (located in config/deploy.rb):
1 set :revision, 'branch_name'
But then I got this error when executing rake vlad:deploy:
1 git checkout: updating paths is incompatible with switching branches/forcing 2 Did you intend to checkout 'branch_name' which can not be resolved as commit?
I managed to solve the problem by using the SHA1 hash of the branch instead of the branch name, but that only worked for the current revision:
1 set :revision, 'd34360870be6536992e6d45bb0aa72eca31e14443'
So after some googling I found this post at scie.nti.st, which made my day because it has the following examples of how to deploy tags and branches with git and Vlad:
1 # Deploy the latest code, this the default 2 set :revision, "HEAD" 3 4 # Deploy branch "origin/branch_name" 5 set :revision, "origin/branch_name" 6 7 # Deploy tag "1.0" 8 set :revision, "1.0"
Note that you have to push the branch to the remote server before running rake vlad:deploy:
1 git push origin branch_name
Installing git without getting screwed over when it's time to uninstall, upgrade or install package maintainer's version
Although Git is one of the better source code managers it has a major drawback if you need to install it from the sources – it’s makefile doesn’t have an uninstall target as defined in the GNU coding standards. Therefore you might find your system screwed over when you want to uninstall or upgrade after installing from sources. This is a workaround that is sufficient enough to make me break my rule of not installing software outside of package management.
Also see the snippet for an alias for the make command first.
Prequisities
1 sudo apt-get install asciidoc xsltproc xmlto xstow bzip2 build-essential zlib1g-dev tcl8.4
Installation
1 cd /tmp 2 wget http://kernel.org/pub/software/scm/git/git-1.5.5.1.tar.bz2 3 tar xjvf git-1.5.5.1.tar.bz2 4 sudo mv git-1.5.5.1 /usr/src 5 sudo ln -s /usr/src/git-1.5.5.1 /usr/src/git 6 cd /usr/src/git 7 ./configure --prefix=/usr/local/stow/git 8 make all doc 9 sudo make install install-doc 10 cd /usr/local/stow 11 cat << EOF > /tmp/xstow.ini 12 # this is the xtow configuration file 13 # see xstow.ini(5) for details 14 15 # list of links that will be handled as normal directories 16 [traverse-links] 17 keep-targets = true # add targets of the links to the keep-dirs section 18 link = /usr/local/tmp 19 link = /usr/local/var 20 link = /usr/local/man 21 link = /usr/local/share 22 link = /usr/local/share/man 23 link = /usr/local/doc 24 link = /usr/local/info 25 add-if-target = /* # automatic add all absolute links 26 27 # directories that never should be removed 28 [keep-dirs] 29 dir = /usr/local/bin 30 dir = /usr/local/sbin 31 dir = /usr/local/lib 32 dir = /usr/local/include 33 dir = /usr/local/share 34 35 [matches] 36 ignore = *~ # emacs 37 ignore = core # core file 38 ignore = core.* # new style 39 ignore = CVS # CVS directories 40 ignore-regex = [0]+README.* 41 42 # make other stow dirs public 43 [stow-dirs] 44 dir = /usr/local/local/stow 45 dir = /usr/local/local/stow2 46 47 [debug] 48 module = ALL 49 level = 0 50 51 [config-files] 52 in-home = yes 53 in-stow-dir = yes 54 in-other-stow-dirs = yes 55 file = /etc/xstow.ini 56 file = /usr/local/local/etc/xstow.ini 57 58 [links] 59 absolute-paths = false 60 EOF 61 sudo mv -i /tmp/xstow.ini . 62 sudo xstow git
Uninstallation
1 cd /usr/local/xstow 2 xstow -D git 3 sudo rm -rf /usr/local/stow/git
Kind of makes one appreciate the work done by package maintainers, doesn’t it?
Fix for empty ident error using older git
In this snippet- Christian explains how to fix the empty ident error using a bleeding edge git. In older git versions this must be done manually. So if you get this error…
1 *** Environment problem: 2 *** Your name cannot be determined from your system services (gecos). 3 *** You would need to set GIT_AUTHOR_NAME and GIT_COMMITTER_NAME 4 *** environment variables; otherwise you won't be able to perform 5 *** certain operations because of "empty ident" errors. 6 *** Alternatively, you can use user.name configuration variable. 7 8 fatal: empty ident <.....@......com> not allowed
... then add the following parameters to your ~/.bashrc file and source it with . ~/.bashrc (or relogin, alternatively):
1 export GIT_AUTHOR_NAME="Marko Haapala" 2 export GIT_COMMITTER_NAME="Marko Haapala"
Installing/compiling and using git with Ruby on Rails (on Mac OS X Leopard and Debian Linux)
Git is a good alternative to Mercurial, and of course SVN or CVS if you’re still using stone age tools, so in this post I’ll show you how to compile, install and use git with Rails.
Installing git on Mac OS X
First compile and install git:
1 cd /usr/local/src 2 wget http://kernel.org/pub/software/scm/git/git-1.5.4.4.tar.bz2 3 tar jxvf git-1.5.4.4.tar.bz2 4 cd git-1.5.4.4 5 make prefix=/usr/local all 6 make prefix=/usr/local test && echo $? 7 sudo make prefix=/usr/local install
Installing git on Debian
On a Debian installation install git by first executing the following commands:
$ sudo apt-get install git-coreNote that the package name is git-core not git.
If you want the latest and greatest version, you first need to install the dependencies (note that you can leave out tk and expat):
1 sudo apt-get install curl 2 sudo apt-get install libcurl3 3 sudo apt-get install libcurl3-dev 4 sudo apt-get install tk8.4 5 sudo apt-get install cpio expat 6 sudo apt-get install zlib 7 sudo apt-get install build-essential 8 sudo apt-get install zlib1g-dev 9 sudo apt-get install asciidoc 10 sudo apt-get install xmlto
Then compile and install:
1 NO_EXPAT=yes NO_SVN_TESTS=yes NO_IPV6=yes NO_TCLTK=yes make -j2 prefix=/usr all 2 NO_EXPAT=yes NO_SVN_TESTS=yes NO_IPV6=yes NO_TCLTK=yes make -j2 prefix=/usr install
Configuring git
Run these commands to tell git your name and email:
1 git config --global user.name "u name" 2 git config --global user.email x@x.com
Otherwise, you might get this error:
1 *** Environment problem: 2 *** Your name cannot be determined from your system services (gecos). 3 *** You would need to set GIT_AUTHOR_NAME and GIT_COMMITTER_NAME 4 *** environment variables; otherwise you won't be able to perform 5 *** certain operations because of "empty ident" errors. 6 *** Alternatively, you can use user.name configuration variable. 7 8 fatal: empty ident <........@........com> not allowed 9 fatal: The remote end hung up unexpectedly
If you like colorized command output execute these commands:
1 git config --global color.diff auto 2 git config --global color.status auto 3 git config --global color.branch auto
Using git
If all goes well, change to your project directory and run the following commands:
1 git init
This creates the git repository, so we’re now ready to start adding files to it, but first we need to create the git ignore file, which tells git to ignore certain files completely:
1 cat <<EOF<<EOF > .gitignore 2 config/database.yml 3 db/*.sqlite3 4 log/*.log 5 tmp/**/* 6 .DS_Store 7 doc/api 8 doc/app 9 EOFEOF
By default git doesn’t add empty directories—sucks if you ask me—so we’ll create a dummy file in all empty directories with the find and touch commands:
1 find . \( -type d -empty \) -and \( -not -regex ./\.git.* \) -exec touch {}/.gitignore \;
Importing files
We’re now ready to start adding and commiting files, so without thinking execute:
1 git add . 2 git commit -m 'initial import'
This creates the git repository, adds and commits all files that are in the current folder.
Using remote repositories
If you’re like me you’ll want to use a remote repository, so let’s continue the exercise by creating the repository folder on the remote server (Note that commands are executed on the remote server from now on):
1 mkdir /var/lib/git/repositories/project_name
We want the folder to be accessible by users belonging to the git group only:
1 addgroup git 2 chown root.git /var/lib/git/repositories/project_name 3 chmod 770 /var/lib/git/repositories/project_name
Now add yourself—or the user you’ll be using to connect to the remote server—to the git group:
1 usermod -a -G git your_username
Alternatively create a new user:
1 useradd -g git your_username
Now we’re finally ready to copy the local repository to the remote server, which is done with the scp command (Note that commands are executed locally again from now on):
1 scp -rp .git user@server://var/lib/git/repositories/project_name
To let git know that this repository exists we’ll use the git remote command:
1 git remote add project_name ssh://server/var/lib/git/repositories/project_name
This adds the information to .git/config, which might be good to have a quick look at.
Note that if you’re using a non-standard SSH port you need to add the following to your ~/.ssh/config file:
1 Host server 2 Port 1234
Commit files and push them to the remote server
Now change a file and commit and push the changes to the remote server:
1 git commit -m "Me be sleepy" 2 git push project_name
If you get an error such as this it means you need to install git:
1 $ git push project_name 2 username@server's password: 3 sh: git-receive-pack: command not found 4 fatal: The remote end hung up unexpectedly
That’s all…
Miscellaneous problems
error: unable to create temporary sha1 filename ./objects/obj_FUu2jb: Permission denied
Resources
http://jointheconversation.org/railsgit
http://devblog.michaelgalero.com/2007/12/17/my-git-notes-for-rails/
http://railscasts.com/episodes/96
http://groups.google.com/group/rails-oceania/browse_thread/thread/2c8611dc93917952/e175f72310823547
http://www.kernel.org/pub/software/scm/git/docs/tutorial.html
http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way