-6

I have installed git version 2.2, but I cannot do "git stash" and 'git pull" on my directory. I am getting following error message when running the git stash and git pull

fatal: Not a git repository (or any of the parent directories):

Can anybody help how to make my working directory as a git repository ?

Tom
  • 141
  • 10
  • What have you tried so far? What output are you getting when trying those two commands? – c4urself Dec 15 '14 at 21:19
  • I have a directory called "mydir" while running command "git stash" inside mydir it shows the error fatal: Not a git repository (or any of the parent directories): I just want to know how can I make my mydir a git repository ? – Tom Dec 15 '14 at 21:27
  • that means directory in which you are currently in is not part of git repository. You first need to initialize new repository, then you can use git commands that work with repository. – Hrvoje Špoljar Dec 15 '14 at 21:43
  • 1
    This question appears to be off-topic because the user just needs to read the error message. – EEAA Dec 15 '14 at 21:54
  • @EEAA what are you trying to explain ? If it is not the part of server fault I would like to request the moderators to move it to the appropriate forum – Tom Dec 15 '14 at 22:06
  • it seems "github" tags are available in serverfault while posting a question, if tags are available there how can it become an off-topic Question ? – Tom Dec 15 '14 at 22:19
  • 1
    @Tom: I'm not migrating this - it would be closed on [SO] as well. – Sven Dec 15 '14 at 22:22
  • @Sven Thanks.. Just follow your rules as a moderator as I would like to appreciate you for the same, but feeling bad for defaming my question as this much by your folks... – Tom Dec 15 '14 at 22:27
  • 1
    @tom No one is defaming you nor your question. The downvote is just indicating that you didn't do much research on your own (a.k.a. reading the error message that was displayed). Don't take it personally. Next time, just try and do a bit of your own research into the issue. – EEAA Dec 15 '14 at 23:24

1 Answers1

0

Based on your comment, the problem is simply that you haven't yet initialized a git repository within your directory.

Git stores data and metadata within the .git directory, stored in the top level of the git repository. If the repository has not yet been initialized, there is no "clean state" to which git stash can revert the files. You'll need to create the repository, and then make a commit, and only then will you be able to stash subsequent changes.

As you seem to be fairly new to git, I'd strongly recommend staying away from 'stash' and keeping with commits to separate branches if you need to tuck your changes away somewhere. Stashes get messy, fast.

mkdir mygit || exit -1
cd mygit
git init 
date > file.txt
git add file.txt
git commit -m 'My initial commit'
date >> file.txt
git status
git diff
git stash
git status 
git diff
cd ..
rm -rf mygit

Here's an example, straight from the shell:

$ mkdir mygit || exit -1
$ cd mygit
$ git init
Initialized empty Git repository in /Users/dfarrell/mygit/.git/
$ date > file.txt
$ git add file.txt
$ git commit -m 'My initial commit'
[master (root-commit) 21de065] My initial commit
 1 file changed, 1 insertion(+)
 create mode 100644 file.txt
$ date >> file.txt
$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   file.txt

no changes added to commit (use "git add" and/or "git commit -a")
$ git diff
diff --git a/file.txt b/file.txt
index 99e9a80..8dcda34 100644
--- a/file.txt
+++ b/file.txt
@@ -1 +1,2 @@
 Mon Dec 15 16:00:32 CST 2014
+Mon Dec 15 16:00:32 CST 2014
$ git stash
Saved working directory and index state WIP on master: 21de065 My initial commit
HEAD is now at 21de065 My initial commit
$ git status
On branch master
nothing to commit, working directory clean
$ git diff
$ cd ..
$ rm -rf mygit
$
erik258
  • 766
  • 5
  • 9