Lately I have been working on a Ruby project that has a bunch of different branches that various developers are working on. One of the development servers has multiple virtual hosts and at certain points in the code release cycle the various virtual hosts could be completely split from the main branch of Ruby code either because of a bug fix, a specific feature, or any number of other reasons. The other night I needed to bring one of the virtual hosts to a near production release to test some features of a product that uses the web application to record data and when I attempted to “git pull” I received an error which is described in detail below along with what I ended up doing to resolve the problem.
git pull ERROR:
- [web@dev project]$ git pull
- error: Unable to append to .git/logs/refs/remotes/origin/master-2223-user-intake: Permission denied
- From email@example.com:example/project
- ! 22c22c4..77c7ccb master-2223-user-intake -> origin/master-2223-user-intake (unable to update local ref)
- error: some local refs could not be updated; try running 'git remote prune origin' to remove any old, conflicting branches
As you can see in the above error it appears that for whatever reason the above git branch is out of sync, has the incorrect permissions, or some other issue. At the time that the “git pull” command was issued the branch that was active is called “prod” for the projects production branch. Initially I attempted to run “git remote prune origin” to resolve the issue however after issuing the command and attempting to run “git pull” again I ended up with the same “Permission denied” error that existed initially. After I listed the contents of the “.git/logs/refs/remotes/origin/” directory the problem was easy to see and to resolve as shown below.
File Listing Of .git/logs/refs/remotes/origin:
- [root@dev origin]# ls -alh
- total 64K
- drwxrwxr-x 2 web web 4.0K Apr 26 14:57 .
- drwxrwxr-x 3 web web 4.0K May 26 2009 ..
- -rw-rw-r-- 1 web web 181 May 26 2009 HEAD
- -rw-rw-r-- 1 web web 20K Apr 26 14:45 master
- -rw-rw-r-- 1 web web 153 Sep 17 2009 master-1770-captcha
- -rw-rw-r-- 1 web web 153 Feb 24 09:25 master-2081-popup-validation
- -rw-r--r-- 1 root root 152 Mar 31 15:08 master-2140-system-timeout-group
- -rw-r--r-- 1 root root 152 Mar 31 15:08 master-2223-user-intake
- -rw-rw-r-- 1 web web 8.9K Apr 26 14:45 prod
- -rw-rw-r-- 1 web web 459 Aug 26 2009 rails-18.104.22.168
As you can see there are two branches in the origin directory with incorrect permissions as I was attempting the “git pull” command as the web user. It appears that at some point one of the developers accidentally added branches or synced branches as the root user so when the 2140 and 2223 branches were added they were owned by the root user. To resolve the issue I simply changed ownership of the files to the proper user and then issued the “git pull” command again to verify the problem was resolved.
Change Origin Directory Git Branch Permissions:
- [root@dev origin]# chown web.web /home/web/project/.git/logs/refs/remotes/origin/*
After modifying the ownership of the files to the proper “web” user I was able to issue the “git pull” command to update the correct branch without issue.