0

I have a local repo that I want to push to github. But it doesn't push, because it thinks that the working tree is clean.

This is the output:

shmuel@nixos  ~/nixos   master ±  git add . && git commit -m config && git push origin master [master ab79eda] config 1 file changed, 1 insertion(+) To github.com:shmu26/NIX.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'github.com:shmu26/NIX.git' hint: Updates were rejected because the remote contains work that you do not hint: have locally. This is usually caused by another repository pushing to hint: the same ref. If you want to integrate the remote changes, use hint: 'git pull' before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. ✘ shmuel@nixos  ~/nixos   master  git add . && git commit -m config && git pull origin master On branch master nothing to commit, working tree clean ✘ shmuel@nixos  ~/nixos   master  git add . && git commit -m config && git push origin master On branch master nothing to commit, working tree clean 

I set up the credentials, but when I try to push, it says that first I need to pull. So I pull. Then, when I try again to push, it says the tree is clean. So nothing gets pushed.

1
  • This usually happens when there are commits on remote that don't have in local. They are not synchronized. So you may try pull first then push. If it won't work try force push. But remember, this will overwrite changes in remote Commented Mar 26, 2024 at 5:35

1 Answer 1

0

error is not on git push command rather in git add and git commit

nothing to commit, working tree clean

That's because:

The git pull command is actually a combination of two other commands, git fetch followed by git merge. In the first stage of operation git pull will execute a git fetch scoped to the local branch that HEAD is pointed at. Once the content is downloaded, git pull will enter a merge workflow. A new merge commit will be-created and HEAD updated to point at the new commit. source

So, after you run git pull command, git is creating a new merge commit (if there is no merge conflicts).

As a result your working tree is clean and can't stage nor commit. If you are okay with git created commit, you should just push it to remote

git pull origin master && git push origin master

If it is not what you want, you can use git fetch and merge as you like.

Or you can use rebase option as outline in this answer

git pull --rebase <remote-name> <branch-name>

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.