Reputation: 7056
I am quite new to git, and I had been working on a small side project for the last 2 months and had been pushing stuff onto bitbucket with no problems. A couple of days ago, I zipped my project folder (since I had to reinstall my Linux OS) and now unzipped this after my reinstallation of Linux OS.
So, now, I went to my project folder, kept happily working and finally did:
git add -A && git commit -m "modified code" && git push origin master
..which is what I usually do..
and I get:
To https://[email protected]/johnsproject/proj.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://[email protected]/johnsproject/proj.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
I have had a look at a few SO questions where they suggest the use of a force flag -f
- but I am unsure if I should be doing this.
p.s: I am on the master branch - which is the only
branch on my repo.
Would really appreciate if anyone could point me in the right direction here.
Thanks.
Upvotes: 17
Views: 59896
Reputation: 16
Sometimes, there might be chances in your branch also, let say you are working on some other branch named "X" in this branch 2 or more people or working. And if you taken the pull from master and then pushing to this "x" branch, will through this error. you need to pull again from "X" branch and push to "X" branch.
Upvotes: 0
Reputation: 691
I had the exact same problem. Nothing helped untill I tried this:
git pull --rebase origin master
After that, run push command i.e.
git push -u origin master
SOLVED FOR ME!!
Upvotes: 2
Reputation: 430
You can try git pull, after that git commit in studio, and after that git push origin branch name.
Upvotes: 0
Reputation: 539
in my case was new file from git repository not added, and this was the solution 1. git status (just to check) 2. git add . 3. git push -u master origin
Upvotes: 0
Reputation: 292
I had the same problem. I fixed by using the git push -f
command which forces the update.
Upvotes: 9
Reputation: 2671
Try doing
git pull origin master
git add -A
git commit -m "modified code"
git push origin master
Your local repository is likely out of sync with the remote repository.
Upvotes: 11
Reputation: 44377
There are changes in the central repository that you must pull before you can push. Do
git add -A
git commit -m "my local changes"
git pull
Resolve any conflicts. Then do
git push
Alternatively, if you have no valuable modifications locally, you can create a new clone of your repo, and start working from there:
git clone https://[email protected]/johnsproject/proj.git new_repo_dir
Upvotes: 24