5

I created a repo directly on GitHub using by browser, than using git bash cloned the repo to my machine, I was able to do a test commit with bash using the readme file.

I keep getting fatal: This operation must be run in a work tree when running git --work-tree=yourSrcFolder add .

Was looking here and here for some clue but after 4 hours ready to give up on ever using Git.

5
  • Why are you trying to use --work-tree? If you're not in the repo, you probably need to be adding --git-dir too... but this is an unusual way to use git. Commented Jan 25, 2013 at 22:58
  • 1
    where did you clone the repo to and where did you try to commit the file from. It needs to be from the same directory. i.e if you clone into git-repo, you need to go into git-repo first before trying to add/commit the file Commented Jan 25, 2013 at 22:59
  • Just copy the files into your cloned repo and use git add instead. --work-tree looks like a backwards way of doing things. Commented Jan 25, 2013 at 23:00
  • @ jszakmeister I am at the root I think(master) Commented Jan 25, 2013 at 23:07
  • @drone.ah cloned to the default location in windows Users\User Commented Jan 25, 2013 at 23:08

3 Answers 3

26

My solution was to create a hard link to the file that is placed in another directory.

You can use ln command (mklink on Windows) to achieve this (assuming that you are currently in the repository directory):

# this will add a file with the same name to the current directory and the same inode
ln ../../filename . 

And then just add it to the git index:

git add filename

And commit it if you need:

git commit -m "add file from another directory"

See inode, ln.

Sign up to request clarification or add additional context in comments.

Comments

1

Simply move any file you wish to add into the repo directory, then add them to the git tracking.

Example: suppose you want to add a file named test.txt to your git repo.

  1. Move it into your repository directory
  2. run git add test.txt
  3. commit the file using git commit -m "Added test file to the repo"
  4. push your modification to the remote server git push

5 Comments

Is there any way to avoid having to add each file ? Like adding whole dir in one go.
git add * will add everything in the directory
Should I add my folder of files under the .git folder or under the master?
I got it thanks now if I could only get GitHub for windows to work. :)
never touch the .git folder. If you need to add a repo just copy the repo into the repo directory and run git add . or git add -A. This will add the repo and its entire content to the git tracking.
0

(Windows version) just add a mklink /j or /J for Directory Junction

at your git dir:

mklink /j DirName "C:\location\SourceDir\"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.