1

First, git/GitHub are largely black boxes to me--I only know how to do very simple things, so it's likely the answer to this is simple.

I was playing around today and realized I had a file in my repository that I didn't want publicly available, so I did all I could to delete it through the GitHub site (with ultimate success). I also deleted the .gitignore and .Rprofile files, the former because I'm not ignoring anything and the latter because I only added that by mistake.

Something here seems to have confused git, as now I'm presented at various stages of debugging with any of the following errors:

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

    .gitignore

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

Figuring git might require a .gitignore file even if it's empty, I restored the file to my directory to no avail:

git add .gitignore
git commit -m 'adding gitignore'
git push origin master

Gives me error:

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/MichaelChirico/real_estate.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.

Then I tried again, trying to get the status before pushing this time:

git add .gitignore
git commit -m 'adding gitignore'
git status

Tells me this:

On branch master
nothing to commit, working directory clean

Basically I'm lost as to what's going on. I've searched around for a while but couldn't find anything helpful (mainly comments about looking for discrepancies in the .gitignore file) so I'm giving up and posting here.

I saw this post, but couldn't understand the answer.


Update: @Makoto requested the output of git branch -vv:

* master 1a5db95 fixing .gitignore
Community
  • 1
  • 1
MichaelChirico
  • 33,841
  • 14
  • 113
  • 198

2 Answers2

1

You need to pull before you can push.

git pull

Then, you should be able to push. Be vigilant for merge conflicts before you do so, as any code with those conflict markers will not compile.


With the new information you've given us, be sure that your master branch is tracking the remote.

Use git branch --set-upstream-to=origin/master to ensure that the local branch is tracking changes from remote, then do a git fetch to be sure that you have the latest stuff (this doesn't merge the changes in automatically).

Makoto
  • 104,088
  • 27
  • 192
  • 230
  • I get the feeling this didn't work from the message `There is no tracking information for the current branch. Please specify which branch you want to merge with.`; I tried `git pul master` but that also seems to have failed: `fatal: 'master' does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.` – MichaelChirico Jun 04 '15 at 20:57
  • So there are things you aren't telling us then. Add the output of `git branch -vv` to your question so that we can be sure that you actually *have* a remote repository. From the context of what you're doing, you **do**. – Makoto Jun 04 '15 at 21:00
  • I've added this to the question; I'm not sure how to interpret. I suppose `1a5db95` is the code for the current commit which I've titled `fixing .gitignore`, but not sure how this helps us (e.g. I compared this output to what I got from running `git branch -vv` in another repository of mine that is working fine and they look indistinguishable) – MichaelChirico Jun 04 '15 at 21:10
  • `set-upstream` seems to have engendered some progress, but still can't `git pull`: `CONFLICT (modify/delete): .gitignore deleted in 73320df23c718c8bdca27bba284a6875e9242a67 and modified in HEAD. Version HEAD of .gitignore left in tree. Removing .Rprofile Automatic merge failed; fix conflicts and then commit the result.` – MichaelChirico Jun 04 '15 at 21:34
  • Good! You're in a state where you can push successfully! Resolve the conflict (best of luck with that!) and then push your changes. – Makoto Jun 04 '15 at 21:35
  • Got it. Used [this post](http://stackoverflow.com/questions/1380670/how-do-i-fix-a-merge-conflict-due-to-removal-of-a-file-in-a-branch) to simply remove `.gitignore` and now things seem to be back to normal! Someday I'll be fluent in `git`-speak... someday... – MichaelChirico Jun 04 '15 at 21:39
0

You will need to pull from the server before pushing. The client is complaining that you're pushing new work without having all of the old work first.

This gives you two options:

  1. pull then push
  2. push --force and discard what ever is on the server you don't have
whoisj
  • 398
  • 1
  • 2
  • 10
  • what exactly does "discard whatever is on the server" mean – MichaelChirico Jun 04 '15 at 20:56
  • 1
    Branches in Git are pointers into a graph. If you force a pointer to point to another point in the graph, it is quire possible that there will be nodes that are no longer reachable. Effectively discarded. Not to panic however, as Git provides a reflog as a sort of "recycle bin" to recover if you do this incorrectly - but it isn't trivial. – whoisj Jun 04 '15 at 20:58