34

When using git add . uses the actual path where you're (incase is a git repo). How would I do for using git add, git commit and git push' outside of the working dir? Likegit add /Users/zad0xsis/my-git-repo`.

Can this be achieved?

2
  • To clarify, you want to run the add command in a git repository outside of the current working directory? Commented Oct 6, 2011 at 14:53
  • exactly, really I want to run git add, git commit and git push on a directory outside the working directory Commented Oct 6, 2011 at 14:54

2 Answers 2

40

I had success using the git -C option. Taken from the Git documentation:

Run as if git was started in <path> instead of the current working directory. 

It is very important that the -C option comes before actual command you want to execute:

Wrong: git add . -C some-path Correct: git -C some-path add . 
0

According to the git docs on my system (git 1.7.6) you can adjust the working directory (where the code resides) using --work-tree or $GIT_WORK_TREE and the repository directory (where the git objects reside) using --git-dir or $GIT_DIR. If that doesn't work you could use a wrapper script, e.g.

#!/bin/bash cd /desired/path git "$@" 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.