Issue
I am unable to add any files to git when I give command 'git add .
' in a Git bash session.
It shows error:
'EG' does not have a commit checked out.
fatal : adding files failed.
I am unable to do any operation in Git now.
I tried all git checkout
commands, deleted branches.
I even deleted git bash from my system.
Tried to search commits in Git GUI but there too I found nothing.
Did all this but to no success. Please help me.
Attaching the image of steps I followed and error that I am getting
Solution
Hi so let me tell you the basic steps on how to use git to push something. Just check if you are following all these.
If you have a new project and it does not have git initialized then do: -
git init
then whenever you do some changes in the project folder and save it just go back to git and do:-
git status
if it shows some file names in red that means those files have been changed and now you need to stage the changes you want to commit.
So if you want to stage a single file then copy that file path shown in the bash window and do
git add <file name>
or else if you want to stage all the changes then do
git add .
next step is to commit the staged changes to do that just write:-
git commit -m "<your commit message here>"
one shortcut method of staging all the files and commiting them is
git commit -am "<your commit message here>"
once you have commited the files just simply do
git push
Some additional commands that are useful:-
git branch --- to know the current branch you are on
git checkout <branchname> --- to switch to some other branch
git checkout -b <branchname> --- to create a new branch
git gc --prune=now ---- to clear all the references
I hope this helps
Answered By - Akshay Bhat
Answer Checked By - Pedro (JavaFixing Volunteer)