11

I'm completely new to git. I'm working in Mac Terminal.

Whenever I do a git status in my home directory, all untracked files, files in the stage directory, and committed files in my entire home directory appear. When I do a git log in my home directory, I get the following error:

fatal: bad default revision 'HEAD'

How do I go about correcting this error? How do I get git to stop tracking the contents of my entire home directory without affecting it in its current state?

Thanks in advance, and I apologize for my ignorance. I just do not want to do anything that could be potentially damaging to my home directory.

When I enter git status in the main directory, I get the following:

~ (master) > Kojo$ git status
 On branch master

Initial commit

 Changes to be committed:
   (use "git rm --cached <file>..." to unstage)

    new file:   Desktop/Classes/Person.cpp
    new file:   Desktop/Classes/Person.h
    new file:   Desktop/Classes/Tweeter.cpp
    new file:   Desktop/Classes/Tweeter.h
    new file:   Documents/AoGPMidterm/xcode/TriMesh.h
    new file:   Projects/Testing/Testing/ConditionalClass.cs
    new file:   Projects/Testing/Testing/Lucky_Num.cs
    new file:   Projects/Testing/Testing/NewEnum.cs

 Changes not staged for commit:
   (use "git add/rm <file>..." to update what will be committed)
   (use "git checkout -- <file>..." to discard changes in working directory)

    deleted:    Desktop/Classes/Person.cpp
    deleted:    Desktop/Classes/Person.h
    deleted:    Desktop/Classes/Tweeter.cpp
    deleted:    Desktop/Classes/Tweeter.h
    modified:   Documents/AoGPMidterm/xcode/TriMesh.h
    modified:   Projects/Testing/Testing/Lucky_Num.cs

 Untracked files:
   (use "git add <file>..." to include in what will be committed)

    .3dequalizer/
    .Assimilate/
    .CFUserTextEncoding
    .MacOSX/
    .adobe/
    .android/
    .appletviewer
    .bash_git
    .bash_history
    .bash_profile
    .bashrc
    .bashrcecho
    .bitrock/
    .cache/
    .codeintel/
    .config/
    .cptzzscn
RyPeck
  • 7,830
  • 3
  • 38
  • 58
Kojo Opuni
  • 123
  • 1
  • 1
  • 6
  • 1
    Did you just create this repo? Have you made any commits yet? Typically people get `fatal: bad default revision 'HEAD'` when there haven't been any commits made in the repo yet. Please include the output of `git status`. –  Aug 03 '13 at 20:05
  • I think that I may have created a repo of my main directory in error. The main directory is listed as 'master'. Here is the output I get when I do a `git status`: – Kojo Opuni Aug 03 '13 at 20:09
  • Please list the exact commands that you used to create your repo. Also, please edit your question to include all of this new information. –  Aug 03 '13 at 20:11
  • possible duplicate of [GIT --> fatal: bad default revision 'HEAD'](http://stackoverflow.com/questions/15628720/git-fatal-bad-default-revision-head) – Salvador Dali Apr 02 '14 at 07:57

2 Answers2

17

The reason for that error is because you haven't made an initial commit. But it also looks like you initialized the git repository in the wrong directory.

It looks like you ran the git init command in the wrong directory. Navigate to the directory you originally ran that command in (Looks like it was your Home Directory).

Run ls -la to see all the files in your current directory. You should see a .git directory. This contains all of data git uses to keep track of your work for a repository. Remove that you'll be back just like you were before you ran git. Since you haven't committed any work to the repo, you can safely remove it.

In the future you should run git init in a folder specifically for the project you are working on. All the files and subfiles in that folder should be for your project.

If you are just getting started using git, I highly recommend the Pro Git book, available for free online.

RyPeck
  • 7,830
  • 3
  • 38
  • 58
  • Thank you! That is exactly what I did. I ran the `ls -la` command in terminal, located the .git directory, and deleted it. I feel silly for making the mistake. It wasn't my intention to set up a repository in my home directory. I just started to read the Pro Git. Thank you, RyPeck - and - thank you Cupcake for trying to help me. Cheers! – Kojo Opuni Aug 03 '13 at 23:24
  • 1
    @KojoOpuni Since you're reading Pro Git, I recommend chapters 1-3 and 6-6.5. I learned most of what I know about Git from that book. Please be sure to learn how to rebase, both interactively and non-interactively. –  Aug 04 '13 at 23:51
7

I'm not sure if this is what happened in your case, but you can get the error message from git log

fatal: bad default revision 'HEAD'

if you just made your repo, and you haven't made any commits in it yet. If this is your case, then simply add your files, commit them, and do the log again:

$ git add "*"
$ git commit -m "Your commit message"
$ git log