-1

Im very new to using git and github but I've read the docs and followed all instructions and still dont seem to be able to commit and push my changes to my own repository on Github here https://github.com/davejonesbkk/flask-intro

When I try to push using 'gut push origin master' and after logging in it returns the following:

To https://github.com/davejonesbkk/flask-intro
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/davejonesbkk/flask-intro'
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.

so then I tried to do a 'git pull origin master' as advised in the github docs and it returns the following:

From https://github.com/davejonesbkk/flask-intro
* branch            master     -> FETCH_HEAD
error: The following untracked working tree files would be overwritten    by merge:

app.pyc
config.pyc
models.pyc
posts.db
sample.db
saple.db
test.pyc
venv/.Python
venv/bin/activate
venv/bin/activate.csh
venv/bin/activate.fish

and then maybe a hundred lines or more of basically all the files etc from the root directory of where the app is stored locally and then this:

Please move or remove them before you can merge.
Aborting

however I read that I should be able to get round this problem by having a .gitignore file in my root folder which I already have and this is its contents:

*.pyc
venv
.DS_Store
blog
*.db
coverage
tag.py

Ive read some other questions here on SO about this problem and they all advise using a .gitignore file but I have one so what else do I need to do?

In case it helps this is also the output of my branches and remote branches:

(discover-flask)Davids-MacBook-Air:flask-intro david$ git branch -a
* master
  remotes/heroku/master
  remotes/origin/master
  remotes/upstream/master

(discover-flask)Davids-MacBook-Air:flask-intro david$ git remote -v
heroku  https://git.heroku.com/calm-falls-6315.git (fetch)
heroku  https://git.heroku.com/calm-falls-6315.git (push)
origin  https://github.com/davejonesbkk/flask-intro (fetch)
origin  https://github.com/davejonesbkk/flask-intro (push)
upstream    https://github.com/davejonesbkk/flask-intro (fetch)
upstream    https://github.com/davejonesbkk/flask-intro (push)

Ive pushed successfully to this repository a while back but that was over a month ago and when following a tutorial and Im not sure whats changed since then, as you can see I've also pushed to Heroku since then but that was also done while following a tutorial.

Im on a Mac btw and trying to push files for a Flask app when using virtualenv.

Any help would be greatly appreciated!

Ozgur Vatansever
  • 49,246
  • 17
  • 84
  • 119
easy_c0mpany80
  • 327
  • 1
  • 7
  • 18
  • 2
    Possible duplicate of [failed to push some refs to 'https://github.com/myname/myrepo'](http://stackoverflow.com/questions/14801972/failed-to-push-some-refs-to-https-github-com-myname-myrepo) – Ayush Dec 08 '15 at 05:16

2 Answers2

1

First pull the repo and then use push -f command if the normal push command is not working.

JGCW
  • 1,509
  • 1
  • 13
  • 25
  • you mean 'git pull origin master'? I tried that before and it just returns this Davids-MacBook-Air:flask-intro david$ git pull origin master From https://github.com/davejonesbkk/flask-intro * branch master -> FETCH_HEAD error: The following untracked working tree files would be overwritten by merge: app.pyc config.pyc models.pyc posts.db sample.db saple.db test.pyc venv/.Python venv/bin/activate venv/bin/activate.csh venv/bin/activate.fish venv/bin/activate_this.py venv/bin/easy_install venv/bin/easy_install-2.7 – easy_c0mpany80 Dec 08 '15 at 05:22
  • 'push -f' worked for me though, thanks. Why am I having to do this though? – easy_c0mpany80 Dec 08 '15 at 05:26
  • `push -f` is force and you can possibly rewrite history. This is not advised for shared repos. – squiguy Dec 08 '15 at 05:27
1

For applying you .gitignore file use this

$git add .gitignore

Commit your changes(don't forget use git add command if you have added some new files in your project)

$git commit -am"my commit"

After that try pull one more time

$git pull origin master

Anyway read more about git reset and it --hard key

fedorshishi
  • 1,467
  • 1
  • 18
  • 34