For some reason, I can't push now, whereas I could do it yesterday. Maybe I messed up with configs or something.
This is what happens:
When I use the git push origin master
What my working directory and remote repository looks like:
For some reason, I can't push now, whereas I could do it yesterday. Maybe I messed up with configs or something.
This is what happens:
When I use the git push origin master
What my working directory and remote repository looks like:
If the GitHub repo has seen new commits pushed to it, while you were working locally, I would advise using:
git pull --rebase git push The full syntax is:
git pull --rebase origin master git push origin master That way, you would replay (the --rebase part) your local commits on top of the newly updated origin/master (or origin/yourBranch: git pull origin yourBranch).
See a more complete example in the chapter 6 Pull with rebase of the Git Pocket Book.
I would recommend a:
git push -u origin master That would establish a tracking relationship between your local master branch and its upstream branch.
After that, any future push for that branch can be done with a simple:
git push See "Why do I need to explicitly push a new branch?".
Since the OP already reset and redone its commit on top of origin/master:
git reset --mixed origin/master git add . git commit -m "This is a new commit for what I originally planned to be amended" git push origin master There is no need to pull --rebase.
Note: git reset --mixed origin/master can also be written git reset origin/master, since the --mixed option is the default one when using git reset.
Did anyone try:
git push -f origin master That should solve the problem.
EDIT: Based on @Mehdi ‘s comment below I need to clarify something about
―force pushing. The git command above works safely only for the first commit. If there were already commits, pull requests or branches in previous, this resets all of it and set it from zero. If so, please refer @VonC ‘s detailed answer for better solution.
If you just used git init and have added your files with git add . or something similar and have added your remote branch it might be that you just haven't committed (git commit -m 'commit message') anything locally to push to the remote... I just had this error and that was my issue.
I had same problem. I was getting this problem because i had not made any commit not even initial commit and still i was trying to push.
Once i did git commit -m "your msg" and then everything worked fine.
I find the solution to this problem in github help.
You can see it from:Dealing with non-fast-forward errors
It says:
You can fix this by fetching and merging the changes made on the remote branch with the changes that you have made locally:
$ git fetch origin # Fetches updates made to an online repository $ git merge origin branch # Merges updates made online with your local work Or, you can simply use git pull to perform both commands at once:
$ git pull origin branch # Grabs online updates and merges them with your local work If you are using gerrit, this could be caused by an inappropriate Change-id in the commit. Try deleting the Change-Id and see what happens.
before push you have to add and commit the changes or do git push -f origin master
Remember to commit your changes before pushing to Github repo. This might fix your problem.
Well if none of the above answers are working and if you have messed up something with ssh-add lately. Try
ssh-add -D In my case, this error happened because there was some maintenance happening on our version of GitLab.
You can also fix it by editing the git config file of your project:
Where is it?
.git/config
Add the following lines at the end if they are not.
[branch "master"] remote = origin merge = refs/heads/master
This solved my problem
In my case closing of editor (visual studio code) solved a problem.
Rename your branch and then push, e.g.:
git branch -m new-name git push -u new-name This worked for me.