1

I'm trying to upload an existing project to Github.
I'm using Git 2.3.5 because newer versions are not compatible with Mac OS X Lion (10.7.5).
I've tried to use git add eu because I found in a guide. Result was the following error:

fatal: pathspec 'eu' did not match any files

I've also tried git add . and git add --all. It gave me a new line which was completely blank.

So, how would I upload my existing Maven project to Github?

  • Mac OS X v10.7.5
  • Git V2.3.5

New error:

MBA-10-09:~ myname$ git push -u origin master
To https://github.com/myname/importer.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/myname/importer.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

MBA-10-09:~ myname$ git config --global pull.rebase true
MBA-10-09:~ myname$ git stash
Saved working directory and index state WIP on master: b1c9c72 Added Importer v0.1-Beta
HEAD is now at b1c9c72 Added Importer v0.1-Beta
MBA-10-09:~ myname$ git pull --rebase
warning: no common commits
remote: Counting objects: 10, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 10 (delta 1), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (10/10), done.
From https://github.com/bys1/importer
 * [new branch]      master     -> origin/master
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
There is no tracking information for the current branch.
Please specify which branch you want to rebase against.
See git-pull(1) for details

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master

MBA-10-09:~ myname$ git stash pop
Removing README.md
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    deleted:    README.md

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

    .CFUserTextEncoding
    .bash_history
    .cache/
    .config/
    .cups/
    .dropbox/
    .eclipse/
    .gitconfig
    .gmwoommrc
    .local/
    .m2/
    .mediafire/
    .oracle_jre_usage/
    .p2/
    .sh_history
    .ssh/
    .tkyczxzn
    Applications/
    BuildData/
    BuildTools.log.txt
    Bukkit/
    CraftBukkit/
    Desktop/
    Documents/
    Downloads/
    Dropbox/
    Library/
    Movies/
    Music/
    Pictures/
    Public/
    Spigot/
    apache-maven-3.2.5/
    craftbukkit-1.10.jar
    magic.mgc
    spigot-1.10.jar
    work/


It took 2.42 seconds to enumerate untracked files. 'status -uno'
may speed it up, but you have to be careful not to forget to add
new files yourself (see 'git help status').
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (3eb015298d6369d65ba7551f0f81178b63cc119e)
Priv
  • 812
  • 2
  • 9
  • 23
  • Git doesn't care (or even know) about Java packages or Maven artifact IDs. What is your directory structure? Is your problem with adding new files, or with pushing existing commits? – ChrisGPT was on strike Jul 09 '16 at 20:11
  • I'm trying to upload my project to Github, but git add --all doesn't do anything. – Priv Jul 09 '16 at 20:28
  • I'm new to Github but did not expect this. – Priv Jul 09 '16 at 20:28
  • But you say you have an "existing project". Do you already have a local Git repository holding that project? `git add --all` only adds files that are already tracked. – ChrisGPT was on strike Jul 09 '16 at 20:41
  • I have a Maven project in Eclipse. Don't know if I have any local repository, how can I find out? I'm a noob at Github. – Priv Jul 09 '16 at 21:01
  • I've used: https://blog.idrsolutions.com/2015/06/how-to-host-a-maven-artifact-on-github/ – Priv Jul 09 '16 at 21:11
  • What parts of that article did you follow? It doesn't ever tell you to use `git add --all`, so clearly you haven't followed it exactly. What does `git status` output if you run it in your working directory? – ChrisGPT was on strike Jul 09 '16 at 21:23

1 Answers1

2

The article does mention:

On command/Terminal, navigate to the local GitHub repository you cloned earlier on

That means you must have cloned a GitHub repo first (and first before that: create a repo on GitHub)

cd c:\users\mylogin
git clone https://github.com/<myaccount>/<my-test-repo>.git

It is in c:\users\mylogin\ that you will see a .git folder.

It is in that same repo you can add files and then:

git add "name of generated folder" (in my case git add org) then enter
git commit -m "Sensible commit message"
git push -u origin master

If your git is recent enough (2.5+, take the 2.9), type (only once)

 git config --global rebase.autosquash true
 git config --global pull.rebase true

That way, when you have an error on git push like "Updates were rejected because the remote contains work that you do not have locally", all you need to do is:

git pull

Your local branch will be rebased on top of its updated remote tracking branch (origin/xxx).
And if you had work in progress (not tracked, or just added to the index), it will be stashed for you to allow for the rebase to take place, then poped back into your working tree.

With git 2.3.5, the git config --global pull.rebase true will work.
That leaves you with:

git stash
git pull --rebase
git stash pop
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • What about git 2.3.5? – Priv Jul 10 '16 at 09:24
  • @Priv Simply upgrade your git if you can: http://stackoverflow.com/q/8957862/6309 – VonC Jul 10 '16 at 09:26
  • The newest version of git doesn't seem to be compatible with Mac OS X Lion. – Priv Jul 10 '16 at 09:32
  • @Priv Sure: try again after a `git branch --set-upstream-to=origin/master master` – VonC Jul 10 '16 at 09:55
  • After git stash: `fatal: git-write-tree: error building trees` – Priv Jul 10 '16 at 10:11
  • @priv if you don't have any work in progress, do a git reset --hard, and try again – VonC Jul 10 '16 at 10:19
  • CONFLICT (file/directory): There is a directory with name importer in Stashed changes. Adding importer as importer~Updated upstream CONFLICT (modify/delete): README.md deleted in Stashed changes and modified in Updated upstream. Version Updated upstream of README.md left in tree. – Priv Jul 10 '16 at 10:23
  • @priv yes, you can have conflicts to resolve. Here, try git add . (space dot), the git rebate --continue. – VonC Jul 10 '16 at 10:28
  • git add . doesn't do anything – Priv Jul 10 '16 at 10:33
  • @priv and the rebate --continue? – VonC Jul 10 '16 at 10:36
  • "Did you mean rebase?" – Priv Jul 10 '16 at 10:37
  • @priv, yes sorry, I am on my phone. – VonC Jul 10 '16 at 10:37
  • `README.md: needs merge` `You must edit all merge conflicts and then mark them as revolver using git add` – Priv Jul 10 '16 at 10:46
  • @priv excellent: edit it, remove the merge markers and make sure it's content is correct, then git add ., and git rebase --continue – VonC Jul 10 '16 at 10:51
  • How? I'm a noob at git, sorry – Priv Jul 10 '16 at 10:57
  • @priv, https://help.github.com/articles/resolving-a-merge-conflict-from-the-command-line/, https://confluence.atlassian.com/bitbucket/resolve-merge-conflicts-704414003.html, – VonC Jul 10 '16 at 11:01
  • @Priv `git rebase --continue` should be the next step (as a `git status` should confirm) if you were resolving conflicts. – VonC Jul 10 '16 at 16:30
  • I've managed to push a commit now. It deleted the readme (I don't care about that) but it did not upload my project for some reason. – Priv Jul 10 '16 at 16:36
  • @Priv That would be becuase, now, you would need to version your untracked files: `git add .; git commit -m "your project" ; git push`. – VonC Jul 10 '16 at 16:38
  • MBA-10-09:importer me$ git add . MBA-10-09:importer me$ git commit -m "Added importer" On branch master Your branch is up-to-date with 'origin/master'. nothing to commit, working directory clean MBA-10-09:importer me$ git push -u origin master Branch master set up to track remote branch master from origin. Everything up-to-date – Priv Jul 10 '16 at 16:41
  • @Priv What does a git status reports? – VonC Jul 10 '16 at 16:44
  • MBA-10-09:importer me$ git status On branch master Your branch is up-to-date with 'origin/master'. nothing to commit, working directory clean – Priv Jul 10 '16 at 16:49
  • @Priv Then all your files should be pushed. If they are not, check if they are ignored (`git check-ignore -v -- afile`) – VonC Jul 10 '16 at 16:52
  • git check-ignore -v -- afile or git check-ignore -v -- importer just gives me a new line – Priv Jul 10 '16 at 16:59
  • @Priv so they are not ignored. If you modify locally one of those files, does a git status reports them as modified? Can you `git add .; git commit -m "small change for testing"; git push` and see if they appear on the remote side? – VonC Jul 10 '16 at 17:00
  • MBA-10-09:importer me$ git push Everything up-to-date – Priv Jul 10 '16 at 17:09
  • @priv are you in a detached head? What git branch returns? – VonC Jul 10 '16 at 17:14
  • Git branch returns master – Priv Jul 10 '16 at 18:22
  • @Priv does it return (`*`) master though, is there a '`*`' ? – VonC Jul 10 '16 at 18:22
  • git branch return `* master` – Priv Jul 10 '16 at 18:26
  • origin https://github.com/bys1/importer.git (fetch) origin https://github.com/bys1/importer.git (push) – Priv Jul 10 '16 at 18:27
  • @Priv next question: what `git log --oneline` returns? does it reference 4e693b6? – VonC Jul 10 '16 at 18:28
  • Yes, on the first line – Priv Jul 10 '16 at 18:30
  • @Priv OK, for testing, can you create a new file, do a `git add -- thatNewFile; git commit -m "test"; git push`? – VonC Jul 10 '16 at 18:31
  • @Priv Fantastic! All you need to do is copy the rest of your file locally where you have created your test file, add; commit and push. And you are done. – VonC Jul 10 '16 at 18:40
  • @Priv Well done, (rm, commit and push would indeed remove that file on the remote side) – VonC Jul 10 '16 at 18:41
  • Thank you, I'm now able to upload files. How would I now upload my Maven project? The guide I stated that I had to use mvn install:install-file ...... but that made folders with groupId, artifactId, version and then a JAR file. – Priv Jul 10 '16 at 18:47