0

I'm having some issues using Git.

I already have a live site hosted on a Digital Ocean droplet. I'd like to push my code to a github repo, and from then do all my development locally. I would push my local code to github and then do updates to the live site by pulling from github.

However, I'm having some trouble getting off the ground.

I already have the repo created and I did a quick git init on the project. I've added the files, made a commit, and then added the repo. However, when I run git push I get this:

fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream github master

So, I ran git push --set-upstream github master. It gave me this error:

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

Can anyone help me create this initial commit to the repo? I'm imagine I'm missing something super basic.

EDIT: I ended up using --force when pushing, and it worked. Thanks.

qotsa42
  • 147
  • 1
  • 1
  • 11

2 Answers2

1

Well this is a stupid answer but, the repository you are using doesn't seem to exist, did you created it ?

If so and it's not public, is it really empty ? A git push --force might be of some use.

silmaril
  • 423
  • 3
  • 10
0

To answer your first question about the upstream error, this is because in order to run git push without any other arguments, you need to have a default remote branch set. This is so that git knows where to send your code. By setting the upstream to github master, you are essentially telling git to run git push github master whenever you run git push. There's a more detailed answer about how it works here.

As for your second question, silmari may be correct that your remote repository (on GitHub) is not actually empty. This could have happened if you chose to add a license file (e.g. MIT) or a .gitignore file when initially setting up the repository on GitHub. In that case, GitHub created a commit for you, which you do not have locally, which is where the conflict arose.

So what I would do first is look at the commit history of your GitHub repo, and see if there are any commits there that you don't have locally. Because you've already made a commit locally, you may have to do a git rebase with your remote branch in order to "clean up" your local history, and be able to push (without resorting to a force push).

Again, much of this is a guess on my part. I hope it helps.

Jonathan Thom
  • 56
  • 1
  • 4
  • I ended up doing a `git push --force` and setting the upstream master and it worked. Looks like I can make commits now, no problem. Thanks for your help. – qotsa42 Apr 01 '19 at 01:19