What part of Git is wrong?

Hello,
I created a test project as follows:

ssh://git@172.20.2.57:22/hack3rcon/test.git
http://172.20.2.57/hack3rcon/test.git

I ran the following commands on my system:

$ git init
$ git remote add origin git@172.20.2.57:hack3rcon/test.git
$ git add .
$ git commit -m "Initial commit"
$ git push -u origin master

But I got the following error:

error: src refspec master does not match any
error: failed to push some refs to '172.20.2.57:hack3rcon/test.git'

What is wrong?

Thank you.

Did git add . actually add any files? If it didn’t, you would get that error.

To check, does git log show any commits?

1 Like

Hi,
Thank you so much for your reply.
The information is as follows:

# ls .git
branches  config  description  HEAD  hooks  info  objects  refs
#
# git commit -m "Initial commit"
Author identity unknown
*** Please tell me who you are.
Run
  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'root@Docker.(none)')
#
# git log
fatal: your current branch 'master' does not have any commits yet

Well, there is your problem. You didn’t add any files to git so there is nothing to be pushed.

So what are these:

Sending a screenshot of some files does not mean you have added those files to git. Git says you haven’t. That’s all I know.

I am pretty sure you have a type in your git add. Do not know what

Git add .

Should do but all tutorials I know are asking to do

Git add *

I used the GitLab template and those files are exist.

Hi,
Thank you so much for your reply.

$ git init
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint: 
hint: 	git config --global init.defaultBranch <name>
hint: 
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint: 
hint: 	git branch -m <name>
Initialized empty Git repository in /home/jason/Downloads/repo/.git/
$ git remote add origin git@172.20.2.57:hack3rcon/test.git
$ git add *
fatal: pathspec '*' did not match any files
$ git add .
$ git commit -m "Initial commit"
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)

$ git push -u origin master
error: src refspec master does not match any
error: failed to push some refs to '172.20.2.57:hack3rcon/test.git'

You know that you need to be in the folder where your files are to use git commands?

So if you do a ll (Linux) or dir (windows) you should see the files

Thank you so much.
So, I must run those commands on the GitLab server and the directory that codes are there. On the GitLab server, they are other projects:

I selected the Banner project and its address is:

@hashed/19/58/19581e27de7ced00ff1ce50b2047e7a567c76b1cbaebabe5ef03f7c3017bb5b7.git

Then:

# cd 19/58/19581e27de7ced00ff1ce50b2047e7a567c76b1cbaebabe5ef03f7c3017bb5b7.git/
# ls
config	gitaly-language.stats  HEAD  info  objects  refs

Ah I think I see what’s going on here. It looks like you expect git remote add origin git@172.20.2.57:hack3rcon/test.git to pull down the repository for you. It will not. It will only tell git where to push/pull from when you tell it to.

In order to get a local copy of the files, what you’d normally do is

git clone git@172.20.2.57:hack3rcon/test.git

This will create a test directory in your current directory with all the files from gitlab and configured to use gitlab to push to / pull from.

1 Like

Hi,
Thank you so much.

The error indicates that there is no branch named “master” on the local computer. This could be because the commit was made without any changes, or the branch was deleted. To resolve the issue, you can try the following:

  1. Make sure your repository has commits. Run git log to view your commit history.
  2. Check if there is a branch named “master”. Run git branch to see a list of branches.
  3. If your repository does not have any commits or a “master” branch, create a new branch and commit.
  4. Then try git push -u origin master again.
1 Like