0

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
Mureinik
  • 297,002
  • 52
  • 306
  • 350
futuredataengineer
  • 442
  • 1
  • 3
  • 14
  • 1
    This is likely to devolve into lots of comments. First `touch` is a *nix command so doesn't exist on windows. Making a README.md file in your editor and saving it will work. Try removing your `myproject` directory, and cloning again and doing `dir` to see what files you have. – doctorlove Dec 13 '21 at 09:00
  • @doctorlove I navigated to the project and posted in the original post what I got. I can't create a README.md from the browser because I don't have that button. But if I go to my computer in the folder, there is a README.md file... – futuredataengineer Dec 13 '21 at 09:12
  • @doctorlove If I delete the folder from my computer and clone it again, it says I have cloned an empty repo. – futuredataengineer Dec 13 '21 at 09:18

2 Answers2

1

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.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • I now deleted the directory in my computer, cloned it again, navigated to it, switched to a new branch "main", but now the last two commands failed, like you said. Silly question, but how do I create the `README.md` file? There is no option in the web interface and I thought I could do it with git add. – futuredataengineer Dec 13 '21 at 09:26
  • OK, I used bash and added it, it is in my folder on my computer. But it's still not on the web browser. – futuredataengineer Dec 13 '21 at 09:27
  • `git add` just stages a file to be committed, it doesn't create it - you'll have to do that in some native way of your OS (see, e.g., the link I shared). WRT "there is no option in the web interface" - I think I lost you here. What web interface are you referring to? – Mureinik Dec 13 '21 at 09:29
  • What I wanted to say is that, despite following the commands and commiting (I did everything in bash), and the README.md file appearing in the folder in my system, if I go to the web page of the project, it still says "The repository for this project is empty". – futuredataengineer Dec 13 '21 at 09:31
  • @futuredataengineer Thanks for clraifying. There's a missing step here. These instructions end with creating a commit in your local repository. If you want this change to appear in the remote repository, you need to push it (`git push origin main`). – Mureinik Dec 13 '21 at 09:36
  • It says the following: `remote: A default branch (e.g. main) does not yet exist for myname/myproject remote: Ask a project Owner or Maintainer to create a default branch: remote: remote: https://gitlab.com/myname/myproject/-/project_members remote: To https://gitlab.com/myname/myproject.git ! [remote rejected] main -> main (pre-receive hook declined) error: failed to push some refs to 'https://gitlab.com/myname/myproject.git'` – futuredataengineer Dec 13 '21 at 09:40
  • 1
    @futuredataengineer sounds like a permission issue - see https://stackoverflow.com/q/52026119/2422776 – Mureinik Dec 13 '21 at 09:45
0
  1. Repo-session mandatory Score: 0.00% (Checks completed: 0.00%) Create a new directory called 0x03-git in your alx-zero_day repo.

Make sure you include a not empty README.md in your directory:

at the root of your repository alx-zero_day AND in the directory 0x03-git And important part: Make sure your commit and push your code to Github - otherwise the Checker will always fail.

Repo:

GitHub repository: alx-zero_day