Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

executing a git pull from a different directory

Tags:

git

git-pull

I'm configuring calimoucho (a little play continuos integration server), and for it to work I need to run a command to pull a cloned git hub repository from outside it.

to be more precise, I'll explain it with an example.

I have the following repository

cd /home/sas mkdir apps cd apps mkdir myApp cd myApp git init echo "my file" > file git add . git commit -m "initial commit" 

Just a silly test repository where my app is supossed to be

Now I need to clone that repository to a checkout folder.

cd /home/sas mkdir calimoucho cd calimoucho mkdir checkout cd checkout git clone /home/sas/apps/myApp/  

so I have the following directory structure

~/apps     myapp       .git       file ~/calimoucho     checkout       myapp         .git         file 

The continuos integration server will have to pull new changes from ~/apps/myapp to ~/calimoucho/checkout/myapp, running a command line sentence from ~/calimoucho

I try with the following command

~/calimoucho$ git --git-dir=/home/sas/apps/myApp/.git --work-tree=/home/sas/calimoucho/checkout/myApp/ pull 

and I get the following error

fatal: /usr/lib/git-core/git-pull cannot be used without a working tree. 

if I don't specify the --work-tree option, the pull is issued, but changes are applied to ~/calimoucho folder instead of ~/calimoucho/checkout/myApp

any idea how to update the cloned repo from the ~/calimoucho folder?

thanks a lot

like image 553
opensas Avatar asked Oct 01 '11 20:10

opensas


2 Answers

I had this question, too. I found the answer in the git documentation (https://git-scm.com/docs/git).

Run the command

git -C <git-working-directory> pull <git remote> 

The specific command to answer this question is

git -C checkout/myApp/ pull 

Note that it is important -C <git-working-directory> comes before the pull command and any additional pull options can be specified at the end of the command. In the example above, the git clone command would have setup the default remote repository ~/apps/myapp so it is not required to specify the remote repository.

like image 67
Danny Avatar answered Sep 16 '22 14:09

Danny


git -C ~/Documents/blar/blar/directory/ pull

This worked for me after hours of searching. I'm on a Mac in Terminal.

like image 39
user14827129 Avatar answered Sep 17 '22 14:09

user14827129