Git push won't do anything (everything up-to-date)

GitDvcs

Git Problem Overview


I'm trying to update a Git repository on GitHub. I made a bunch of changes, added them, committed then attempted to do a git push. The response tells me that everything is up to date, but clearly it's not.

git remote show origin

responds with the repository I'd expect.

Why is Git telling me the repository is up to date when there are local commits that aren't visible on the repository?

  [searchgraph]  git status
# On branch develop
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       Capfile
#       config/deploy.rb
nothing added to commit but untracked files present (use "git add" to track)

  [searchgraph]  git add .

  [searchgraph]  git status
# On branch develop
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       new file:   Capfile
#       new file:   config/deploy.rb
#

  [searchgraph]  git commit -m "Added Capistrano deployment"
[develop 12e8af7] Added Capistrano deployment
 2 files changed, 26 insertions(+), 0 deletions(-)
 create mode 100644 Capfile
 create mode 100644 config/deploy.rb

  [searchgraph]  git push
Everything up-to-date

  [searchgraph]  git status
# On branch develop
nothing to commit (working directory clean)

Git Solutions


Solution 1 - Git

git push doesn't push all of your local branches: how would it know which remote branches to push them to? It only pushes local branches which have been configured to push to a particular remote branch.

On my version of Git (1.6.5.3), when I run git remote show origin it actually prints out which branches are configured for push:

Local refs configured for 'git push':
  master pushes to master (up to date)
  quux   pushes to quux   (fast forwardable)

Q. But I could push to master without worrying about all this!

When you git clone, by default it sets up your local master branch to push to the remote's master branch (locally referred to as origin/master), so if you only commit on master, then a simple git push will always push your changes back.

However, from the output snippet you posted, you're on a branch called develop, which I'm guessing hasn't been set up to push to anything. So git push without arguments won't push commits on that branch.

When it says "Everything up-to-date", it means "all the branches you've told me how to push are up to date".

Q. So how can I push my commits?

If what you want to do is put your changes from develop into origin/master, then you should probably merge them into your local master then push that:

git checkout master
git merge develop
git push             # will push 'master'

If what you want is to create a develop branch on the remote, separate from master, then supply arguments to git push:

git push origin develop

That will: create a new branch on the remote called develop; and bring that branch up to date with your local develop branch; and set develop to push to origin/develop so that in future, git push without arguments will push develop automatically.

If you want to push your local develop to a remote branch called something other than develop, then you can say:

git push origin develop:something-else

However, that form won't set up develop to always push to origin/something-else in future; it's a one-shot operation.

Solution 2 - Git

This happened to me when my SourceTree application crashed during staging. And on the command line, it seemed like the previous git add had been corrupted. If this is the case, try:

git init
git add -A
git commit -m 'Fix bad repo'
git push

On the last command, you might need to set the branch.

git push --all origin master

Bear in mind that this is enough if you haven't done any branching or any of that sort. In that case, make sure you push to the correct branch like git push origin develop.

Solution 3 - Git

Please try going to the last commit and then do git push origin HEAD:master.

Solution 4 - Git

Try:

git push --all origin

Solution 5 - Git

For my case, none of other solutions worked. I had to do a backup of new modified files (shown with git status), and run a git reset --hard. This allowed me to realign with the remote server. Adding new modified files, and running

git add .
git commit -am "my comment"
git push

Did the trick. I hope this helps someone, as a "last chance" solution.

Solution 6 - Git

Right now, it appears as you are on the develop branch. Do you have a develop branch on your origin? If not, try git push origin develop. git push will work once it knows about a develop branch on your origin.

As further reading, I'd have a look at the git-push man pages, in particular, the examples section.

Solution 7 - Git

Thanks to Sam Stokes. According to his answer you can solve the problem with different way (I used this way). After updating your develop directory you should reinitialize it

git init

Then you can commit and push updates to master

Solution 8 - Git

To be specific, if you want to merge something to master, you can follow the below steps.

git add --all // If you want to stage all changes other options also available
git commit -m "Your commit message"
git push // By default when it clone is sets your origin to master or you would have set sometime with git push -u origin master.

It's a common practice in the pull request model create to a new local branch and then push that branch to remote. For that you need to mention where you want to push your changes at remote. You can do this by mentioning remote at the time of push.

git push origin develop // It will create a remote branch with name "develop".

If you want to create a branch other than your local branch name you can do that with the following command.

git push origin develop:some-other-name

Solution 9 - Git

This happened to me when I ^C in the middle of a git push to GitHub. GitHub did not show that the changes had been made, however.

To fix it, I made a change to my working tree, committed, and then pushed again. It worked perfectly fine.

Solution 10 - Git

This happened to me. I just re-committed the changes, and then it pushed.

Solution 11 - Git

Follow The Steps:

  1. git log
  2. git remote -v [Check Wheather any Origin is there or not]
  3. [IF NO ORIGIN] git remote add origin yourOriginName eg: git remote add origin https://github.com/vikaskumar27071990/RandomCodes.git
  4. git status
  5. git push -u origin master

(IF YOU GETTING ERROR LIKE master set up to track remote branch master from origin THEN FOLLOW BELOW POINTS)

  1. git init
  2. git add -A
  3. git commit -m 'Fix bad repo'
  4. git push

On the last command, you might need to set the branch.

git push --all origin master

Solution 12 - Git

Instead, you could try the following. You don't have to go to master; you can directly force push the changes from your branch itself.

As explained above, when you do a rebase, you are changing the history on your branch. As a result, if you try to do a normal git push after a rebase, Git will reject it because there isn't a direct path from the commit on the server to the commit on your branch. Instead, you'll need to use the -f or --force flag to tell Git that yes, you really know what you're doing. When doing force pushes, it is highly recommended that you set your push.default config setting to simple, which is the default in Git 2.0. To make sure that your configuration is correct, run:

$ git config --global push.default simple

Once it's correct, you can just run:

$ git push -f

And check your pull request. It should be updated!

Go to bottom of How to Rebase a Pull Request for more details.

Solution 13 - Git

I tried many methods including defined here. What I got is,

  • Make sure the name of repository is valid. The best way is to copy the link from repository site and paste in git bash.

  • Make sure you have commited the selected files.

      git commit -m "Your commit here"
    
  • If both steps don't work, try

    git push -u -f origin master

Solution 14 - Git

This happened to me once I tried to push from a new branch and I used git push origin master instead. You should either:

  • Use: git push origin your_new_branch if you want that this branch occurs too in the remote repo.
  • Else check out to your master branch merge things then push to from master to git repo with git merge origin master.

> Recap: the point here is that you should check out where you offer on > the second parameter for git merge. So if you are in the master use > master as the second parameter if you are in the new_branch use this > as the second parameter if you want to keep this branch in the remote > repo else opt for the second option above instead.

Solution 15 - Git

In my case, I had to delete all remotes (there were multiple for some unexplained reason), add the remote again, and commit with -f.

$ git remote
origin
upstream

$ git remote remove upstream
$ git remote remove origin
$ git remote add origin <my origin>
$ git push -u -f origin main

I don't know if the -u flag contributed anything, but it doesn't hurt either.

Solution 16 - Git

The problem could also be that the local branch does not have an upstream.

use:

git push --set-upstream origin main

You are setting up what branch you are pushing the files to.

Solution 17 - Git

Are you sure you have the right remote origin url set ? By issuing git remote show origin are "Fetch URL" and "Push URL" set correctly according to your repository url ?

That was my mistake, I entered it manually and it was not the right path.

Solution 18 - Git

It may happen when you are in a branch different than the one you think, let's call it "append". You need to return to main locally and push from there. But be careful, when you return to main, all your changes will be undone, and you will see only the code until the last edit of your local main.

Solution 19 - Git

if are adding new project to github you can use below steps :

rm -rf .git/
git init
git remote add origin https://repository.remote.url
git add .
git commit -m “Commit message here”.
git push -f origin master

Solution 20 - Git

Try git add -A instead of git add .

Solution 21 - Git

git push origin master

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJamie WongView Question on Stackoverflow
Solution 1 - GitSam StokesView Answer on Stackoverflow
Solution 2 - GitVikView Answer on Stackoverflow
Solution 3 - GituruapanmexicansongView Answer on Stackoverflow
Solution 4 - GitasandroqView Answer on Stackoverflow
Solution 5 - GitAndreaView Answer on Stackoverflow
Solution 6 - GittheIVView Answer on Stackoverflow
Solution 7 - GitNadir HajiyevView Answer on Stackoverflow
Solution 8 - GitManuView Answer on Stackoverflow
Solution 9 - GithelsontView Answer on Stackoverflow
Solution 10 - Gituser742102View Answer on Stackoverflow
Solution 11 - GitVikas kumarView Answer on Stackoverflow
Solution 12 - Gituser4398985View Answer on Stackoverflow
Solution 13 - GitDeveloper HereView Answer on Stackoverflow
Solution 14 - GitDINA TAKLITView Answer on Stackoverflow
Solution 15 - GitMark JeronimusView Answer on Stackoverflow
Solution 16 - GitChasten PoundsView Answer on Stackoverflow
Solution 17 - GitBrahim SlitiView Answer on Stackoverflow
Solution 18 - Git9395View Answer on Stackoverflow
Solution 19 - GitMANISHView Answer on Stackoverflow
Solution 20 - GitionmanView Answer on Stackoverflow
Solution 21 - GitivansView Answer on Stackoverflow