120

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)
1
  • Also make sure you're pushing to the correct branch.
    – Brian
    May 29, 2010 at 21:37

22 Answers 22

159

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.

7
  • Thanks a lot , your git push origin develop:something-else has given answer to question i was not able to get for a while.
    – Antroid
    Apr 13, 2017 at 17:45
  • 1
    In my case git push origin x was still not setting up branch x to be pushed in the future. It was due to a specific pushspec in .gitconfig [remote "origin"] section which was causing git's behavior.
    – Raman
    Jul 26, 2017 at 4:31
  • Using only git push origin I had this problem, using your example git push origin develop and accommodating it to my master branch git push origin master the problem was solved, thanks
    – FantomX1
    Sep 7, 2020 at 18:03
  • If you ever get the fantastic idea of aha so probably if I do git push :target_branch it will assume I want to push my current branch - no, it will delete the remote branch
    – user10706046
    Mar 24, 2021 at 9:21
  • This helped. Thank you Jul 22, 2021 at 21:21
36

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.

20

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

4
  • 1
    This actually worked. Would you like to explain why it worked? Jul 30, 2017 at 19:15
  • 1
    Textually from docs: Push the current branch to the remote ref matching master in the origin repository. This form is convenient to push the current branch without thinking about its local name. Aug 1, 2017 at 18:49
  • Worked for me as well Nov 3, 2019 at 19:12
  • I compared how my repo is configured and all branches looked the same. Yet, in one branch I couldn't simply use git push :/ This worked for me as well: git push origin HEAD:my_branch_name.
    – iaforek
    Nov 25, 2019 at 10:00
16

Try:

git push --all origin
2
  • this pushes the commits to separate branches on the repo, not from one branch into master.
    – Sreedevi J
    Jul 29, 2015 at 10:50
  • This helped me. I entered git push origin/myBranch instead of git push origin myBranch and commit was not in repository... git diff or git status - nothing to commit... after git push --all origin was everything ok... commit in repo appears... in right branch. Thank you. Jul 20, 2022 at 9:36
5

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.

0
5

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.

3

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

1
  • 1
    Thanks! In my case, type: git init and open a new command tab, type: git push origin branch_name
    – s7ven
    Jun 26, 2019 at 17:22
3

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
2

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.

2

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

2

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

1

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.

1

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

1

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.

1
  • just a note for anyone comparing answers - -u is the shorthand for the --set-upstream flag, and it specifically tells git to which remote branch belongs to your local one
    – Sandra
    Nov 10, 2023 at 12:58
1

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
1
  • in recent times you might want to use the SSH url when you git remote add origin (starts with eg [email protected]: and a default main branch. also be wary of the -f flag - this means you're doing a forced push and overwrite the existing branch on the remote.
    – Sandra
    Nov 10, 2023 at 12:54
0

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.

0

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.

0

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.

0

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.

-1

git commit -m "initial commit"

git push origin main

it worked for me

-2

Try git add -A instead of git add .

0
-6
git push origin master
1
  • Don't know why so many bad votes, this is what worked for me git push origin master, git push origin alone pretend to work, but did not work, who knows if setting upstream or something would help too
    – FantomX1
    Sep 7, 2020 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.