2

I am new to Git/GitHub and am having enormous difficulty pushing my new repo up to GitHub.

I created my project locally, which essentially has the following directory structure:

myapp/
    src/
        <A bunch of source files>
    build.grade
    gradle.properties
    README.md
    .gitignore

For good measure, here's my .gitignore (in case its the culprit):

.idea
*.iml
*.ipr
*.iws
/out
.gradle
/build
/files
/*.yaml
/*.sh

I confirmed Git was installed by running git —version which produces:

git version 2.3.2 (Apple Git-55)

I then created a new GitHub repo (private) and left it empty so I wouldn’t have to merge anything.

I then attempted to init my project as a new git repo and here’s the command-line history:

myuser@mac:~/sandbox/eclipse/workspace/myapp$ git init
Initialized empty Git repository in /Users/myuser/sandbox/eclipse/workspace/myapp/.git/
myuser@mac:~/sandbox/eclipse/workspace/myapp$ git commit -am "Initial barebones commit."

*** 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 'myuser@mac.(none)')
myuser@mac:~/sandbox/eclipse/workspace/myapp$ git config --global user.email "myuser@example.org”
myuser@mac:~/sandbox/eclipse/workspace/myapp$ git config --global user.name “mygithubusername”
myuser@mac:~/sandbox/eclipse/workspace/myapp$ git commit -am "Initial barebones commit."
On branch master

Initial commit

Untracked files:
.classpath
.gitignore
.project
.settings/
README.md
bin/
build.gradle
gradle.properties
gradle/
gradlew
gradlew.bat
src/

nothing added to commit but untracked files present
myuser@mac:~/sandbox/eclipse/workspace/myapp$ git remote add origin https://github.com/mygithubusername/myapp.git
myuser@mac:~/sandbox/eclipse/workspace/myapp$ git push -u origin master
error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/mygithbusername/myapp.git'

So as you can see I tried:

  1. Running git init
  2. Adding and pushing changes to the local repo, but had to first setup my email and username (again I’m brand new to Git here)
  3. Added & committed
  4. Added the new remote repo
  5. Tried pushing to that remote rep

According to this answer, this “src ref spec master does not match any” error may be due to the fact that I have’t actually committed anything yet, which might jive with the “untracked file” errors/warnings I see above it.

Either way, where did I go awry, and what do I do to fix it?

Community
  • 1
  • 1
smeeb
  • 27,777
  • 57
  • 250
  • 447

3 Answers3

3

You must use git add to add your untracked files.

Use the command git add .

  • Thanks @Feix Ribeiro, this worked, but why? Shouldn't my `git -am ...` command have added this for me as well? – smeeb Aug 01 '15 at 18:59
  • @smeeb when a new file is created in a git repository its status is "untracked". It means that git is not tracking the file's changes. So, when you do ```git add``` you're saying "Ok git, you can work on these files now". Then, the file changes to "tracked" status. When any modification occurs in the file, git will show that the file is modified. Here you can use -am parameter to ```git commit```. Got it? – Felix Ribeiro Aug 04 '15 at 10:41
1

According to your log, it doesn't look like you added your files (to be tracked) before committing.

Using git commit -am isn't enough, because it only adds modified files (that is, files that are already part of your repo). You're on your initial commit, so there aren't any files in the index yet.

To add (stage) all the files in your current directory, use git add . before you commit. Alternately, use git add <filename1> <filename2> ... to stage individual files for commit.

Then you can use git status to verify the files you want to add to your commit are staged to be committed. They should show up as green if they are properly staged (under a heading that says "Changes to be committed". Files that are not staged to be committed will show up as red, under a heading that says "Changes not staged for commit".

More info on git workflow here: https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository

Maximillian Laumeister
  • 19,884
  • 8
  • 59
  • 78
  • Thanks @Maximillian Laumeister (+1) - please see my question underneath Felix's answer, I have the same question for you! – smeeb Aug 01 '15 at 18:59
  • 1
    @smeeb The `-a` flag only adds files that are already in your repository (i.e. modified files). Since this is your first commit, there are no files in your repo yet, so you need to add them manually the first time. I've edited my answer with that detail. – Maximillian Laumeister Aug 01 '15 at 19:05
0

Git's output should look like this:

On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    foo.txt

nothing added to commit but untracked files present (use "git add" to track)

(Note the hint between parenthesis, which would answer your question).

Someone or something has set the configuration variable advice.statusHints to false for your it seems.

Matthieu Moy
  • 15,151
  • 5
  • 38
  • 65