I'm running this code to upload my local folder as a git repo:
cd "Your project directory"
git init
git add .
git commit -m "First commit"
git remote add origin "your GitHub URL"
git push -u origin main
But I get the following error after git add . :
error: 'main/' does not have a commit checked out
fatal: adding files failed
Why? What am I missing?
The output of git status is:
On branch main
Your branch is up to date with 'origin/main'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: PPO_paper.py
modified: PPO_strappo.py
modified: strappo.py
Untracked files:
(use "git add <file>..." to include in what will be committed)
__pycache__/
gym_less_strappo.py
less.py
less_gym.py
less_strappo.py
logs/
main/
models/
no changes added to commit (use "git add" and/or "git commit -a")
CodePudding user response:
This particular message:
error: 'main/' does not have a commit checked out
means that main/
contains a .git
(hidden folder or file) and hence everything in main/
is a second, separate Git repository. Since you are not allowed to add a Git repository to a Git repository,1 Git assumes you mean to add (update) the gitlink half of a submodule. Luckily for you—otherwise Git would go ahead and add a broken submodule—this other second Git repository has no commits in it yet.
If you want a submodule here, use git submodule add
.2 But you probably do not want a submodule here.
If you don't want a submodule here, figure out why there is a main/.git
. Who put it there? When? Why? What did they have in mind? Is it okay to remove it? If you *do *remove it, you'll be able to git add
the files in the main/
subdirectory.
1This is an administrative restriction and exists for multiple reasons, including security. It's not that it's physically impossible to put a Git repository inside a Git repository (although it's generally unwise to do so), it's that it's administratively forbidden.
2Use git submodule add
after creating a commit in the submodule, since the superproject needs to add a specific commit within the submodule.
CodePudding user response:
before you check whether you have created a repo after that you do the git branch command to display all the branches in the repo after successfully displaying you try to continue by repeating to push with the file names that have been checked on the branch