I created a new blank project in GitLab (in the browser). I checked the "Initialize repository with a README" box. But when opening it, it says: "The repository for this project is empty." I assume I still need to initialize a README.md file so that the main branch exists? So in the command line I tried (I am using windows 10):
git clone https://gitlab.com/url/myproject.git
cd myproject
git switch -c main
touch README.md
git add README.md
git commit -m "add README"
But it says:
C:\Users\me>git clone https://gitlab.com/ur/myproject.git
fatal: destination path 'myproject' already exists and is not an empty directory.
C:\Users\me>cd myproject
C:\Users\me\myproject>git switch -c main
fatal: A branch named 'main' already exists.
C:\Users\me\myproject>touch README.md
'touch' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\me\myproject>git add README.md
C:\Users\me\myproject>git commit -m "add README"
On branch main
Your branch is based on 'origin/main', but the upstream is gone.
(use "git branch --unset-upstream" to fixup)
nothing to commit, working tree clean
My project is still empty and I can't add or push anything. Why?
EDIT: If I navigate to the project and do dir
, I get (I only deleted the volume serial number):
C:\Users\me\myproject>dir
Volume in drive C has no label.
Volume Serial Number is ...
Directory of C:\Users\me\myproject
13.12.2021 09:29 <DIR> .
13.12.2021 09:29 <DIR> ..
13.12.2021 09:29 0 README.md
1 File(s) 0 bytes
2 Dir(s) 112.515.997.696 bytes free
CodePudding user response:
Let's break the errors down one by one.
C:\Users\me>git clone https://gitlab.com/ur/myproject.git
fatal: destination path 'myproject' already exists and is not an empty directory.
The myproject
folder already exists - most likely you've already cloned the project, so nothing more to do here.
C:\Users\me\myproject>git switch -c main
fatal: A branch named 'main' already exists.
You can't create a main
branch since it already exists - so again, nothing to do here.
C:\Users\me\myproject>touch README.md
'touch' is not recognized as an internal or external command,
operable program or batch file.
touch
is a *nix command that doesn't exist in Windows. One option is to use Git Bash instead of CMD, which provides a touch
executable. Alternatively, you could use another method to create an empty file in Windows.
C:\Users\me\myproject>git add README.md
C:\Users\me\myproject>git commit -m "add README"
On branch main
Your branch is based on 'origin/main', but the upstream is gone.
(use "git branch --unset-upstream" to fixup)
nothing to commit, working tree clean
These two commands didn't fail, they just did nothing because the README.md
file wasn't created. Once you create it you can repeat these two commands and they should succeed.