Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 904577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:04:33+00:00 2026-05-15T16:04:33+00:00

With svn, I was able to run commands on files in a checkout, without

  • 0

With svn, I was able to run commands on files in a checkout, without having cd into that checkout first. For example:

# Located in /tmp, running svn operation on /home/d5ve/checkout
d5ve@host:/tmp> svn add /home/d5ve/checkout/myfile.txt
d5ve@host:/tmp> svn diff /home/d5ve/checkout/myfile.txt
d5ve@host:/tmp> svn commit /home/d5ve/checkout/myfile.txt

When I attempt this workflow using git, I get an error:

# Located in /tmp, attempting git operation on /home/d5ve/checkout2
d5ve@host:/tmp> git add /home/d5ve/checkout2/myfile.txt
fatal: Not a git repository (or any of the parent directories): .git

I’ve tried using the --git-dir and --work-tree flags, but that also seemed to fail.

Any suggestions git people? I use this workflow a lot and really miss it when using git.

UPDATE 2016 The current correct answer to this is to use the -C flag to git, which was introduced in version 1.8.5 in 2013. See https://stackoverflow.com/a/35899275/357336

UPDATE: Based upon lunaryorn answer below, I’ve created a simple perl script which works out the location of the .git directory from the file paths, and sets the GIT_WORK_TREE and GIT_DIR environmental variables for the command.

Please have a look at: http://github.com/d5ve/rgit

USAGE: rgit COMMAND [ARGS]

Basically just replace git with rgit in a command, and you can run the commands from outside the repository.

cd /tmp    
rgit diff /home/d5ve/checkout1
rgit add /home/d5ve/checkout1/rgit.pl
rgit commit /home/d5ve/checkout1/
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:04:33+00:00Added an answer on May 15, 2026 at 4:04 pm

    You have to use both options together:

    git --git-dir=/home/d5ve/checkout2/.git --work-tree=/home/d5ve/checkout2/ add /home/d5ve/checkout2/myfile.txt
    

    Note, that --git-dir does not refer to the directory containing working copy, but to the .git subdirectory, which contains the repository itself. git provides two environment variables to set these options permanently for a session:

    export GIT_WORK_TREE="/home/d5ve/checkout2"
    export GIT_DIR="${GIT_WORK_TREE}/.git"
    git status
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

svn offer lot of nice commands that make us able to know what is/did
How can I use svn export , svn checkout etc commands in Cygwin? Do
I am trying to run this example http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/doc/PoolingDataSourceExample.java?view=markup but somehow I am not able
I've run into an interesting problem here in using heroku + git + SVN.
I have been told that SVN is a good method of being able to
I've read about the svn move command but haven't been able to use it
I'd like to be able to comment on a particular Revision in SVN (using
I run an SVN server on a linux server. I'm going out of town
Last Thursday I built SVN from source on my Mac running Leopard 10.5.7 so
I'm trying to get my java program to run an svn command from the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.