Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using git: committed changes in one branch affect 'master'

I have an issue with git which I feel may relate to permissions. The situation is as follows: I have two branches, 'master' and 'theming'. The file in question is called 'settings.php', and it has the permissions r--rw-rw-, and the owner listed is my own username. I am using Ubuntu 10.4LTS.

I produce the issue in the following manner:

  1. Checkout the theming branch
  2. Make change to settings.php
  3. Add and commit the change to 'theming'
  4. Checkout 'master' branch by using: $ git checkout master

After the preceding steps, I get the error 'unable to unlink settings.php', and I note that the file has also been changed in master. This also happens if I do it the other way around, ie. I change it in master, commit the change, and checkout theming. It then does not let me change back to the previous branch, as there are changes to be committed.

The only way I know of to avoid running into this issue is using $ sudo checkout [branchname]. This temporarily avoids the issue, but if I ever use checkout without sudo, I run into the same thing again and I have to worry about undoing all of the changes in my current branch.

Does anyone know how to solve this? I've looked around and I find issues relating to unlinking, but none like mine.

like image 426
Paragon Avatar asked Mar 24 '26 11:03

Paragon


1 Answers

You shouldn't be checking it out as root in the first place. Try changing the repository permissions back to you:

# chown -R yourname ~/path/to/your/gitrepo

If you need to use a shared repository, check out the 'git init' manual for the --shared flag. Or there are lots of google hits for group settings that let you properly share a repo, but it is git version dependent so I won't recount it all here. The setting you're probably looking for, if so, is this one:

[core]        
sharedrepository = 0660

(and then chgrp -R the directory and chmod g+s on the directory as well)

like image 137
Wes Hardaker Avatar answered Mar 26 '26 07:03

Wes Hardaker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!