Matthew
Matthew

Reputation: 6609

git pull for a local repository at specified location (instead of pwd)

pwd is "present working directory". Here's the situation.

pwd:            /path/to/pwd/
git repository: /repo/path/.git/

I want to do a git pull from origin, but without changing my current directory.

To clarify just a little more in case I'm not clear enough, this is the result I want, but I want to do it with one command instead of having to change directories:

$ cd /repo/path
$ git pull origin master
$ cd -

Upvotes: 16

Views: 9309

Answers (3)

MorganTimney
MorganTimney

Reputation: 76

The -C [/repo/path/] seems to work for me.

git -C /repo/path/ pull

Of course replacing the /repo/path/... with your actual path. This should work for any git command, like you might want to preface your git pull command with:

git -C /repo/path/ status so you can confirm you are on the right branch

Upvotes: 2

Justin ᚅᚔᚈᚄᚒᚔ
Justin ᚅᚔᚈᚄᚒᚔ

Reputation: 15369

git --work-tree=/repo/path --git-dir=/repo/path/.git pull origin master

Upvotes: 25

sethcall
sethcall

Reputation: 2907

bash -c "cd /repo/path; git pull origin master"

Upvotes: 4

Related Questions