0

I created a script on a database server which I want to add to my remote repository.

I did the following in the directory which the SQL schema script exists

git init
git remote add origin https://my@bitbucket.org/me/myproject.git
git add schema.sql
git commit -m "added schema.sql"

when I do git push I get the following

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 origin master

When I do git push --set-upstream origin master I get

 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://my@bitbucket.org/me/myproject.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I want to add this single file to my remote repository. Is there a simple way of doing this with git?

david
  • 997
  • 3
  • 14
  • 34
  • Instead of doing your workflow, you should just clone the repo directly – Paolo Oct 19 '19 at 14:38
  • Possible duplicate of [Cannot push to GitHub - keeps saying need merge](https://stackoverflow.com/questions/10298291/cannot-push-to-github-keeps-saying-need-merge) – phd Oct 19 '19 at 17:00
  • https://stackoverflow.com/search?q=%5Bgit%5D+hint%3A+Updates+were+rejected+because+the+tip+of+your+current+branch+is+behind – phd Oct 19 '19 at 17:00

2 Answers2

0

Instead of git init && git remote add ... use:

git clone https://my@bitbucket.org/me/myproject.git

Then put your file where it belongs and:

git add schema.sql
git commit -m "added schema.sql"
git push

If you need to push this file to an established repo, then you'll need to pull:

git init
git remote add origin https://my@bitbucket.org/me/myproject.git
git pull
git add schema.sql
git commit -m "added schema.sql"
Stewart
  • 4,356
  • 2
  • 27
  • 59
0

You have added remote repository, committed your changes, but you haven't pulled data from it. So first pull from the repository, then push to it. git pull
git push

equi
  • 729
  • 8
  • 19