Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script for root to git pull as another user

I have a script that I would like to have do a git pull inside another user's git directory. This script is run by the root user. For example:

cd /home/username/GitProject
sudo -u username -i git pull

When I run this, I get:

fatal: Not a git repository (or any of the parent directories): .git

Is there a way to have my script do a git pull as username?

like image 602
nwalke Avatar asked Nov 09 '13 04:11

nwalke


People also ask

How do I pull from one github account to another?

Using the command lineGo into the directory for your project. Add a connection to your friend's version of the github repository, if you haven't already. Pull his/her changes. Push them back to your github repository.

How do I pull git to another computer?

On computer 1, clone the repo, create a branch, push your branch back to github. On computer 2, clone the repo, pull the branch you created down, make a change, and then push it back.


1 Answers

Try without the -i option to sudo. That option is documented as first changing to the target user's home directory, which undoes the directory change you so carefully do before that. Alternatively, use the appropriate options to git to specify the directory, something like this:

sudo -u username -i git --git-dir=/home/username/GitProject/.git --work-tree=/home/username/GitProject pull
like image 85
John Zwinck Avatar answered Oct 06 '22 00:10

John Zwinck