-4

I updated a file and I failed to push a PR because someone changed a file in the repository.

(base) debian@appdev:/mnt/OneTB/bioconda-recipes/recipes$ git add haslr
(base) debian@appdev:/mnt/OneTB/bioconda-recipes/recipes$ git commit
[haslr 38ce3ea87] Changed version number.
 Committer: Debian <debian@appdev.novalocal>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:

    git config --global --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 2 insertions(+), 2 deletions(-)

(base) debian@appdev:/mnt/OneTB/bioconda-recipes/recipes$ git push
Username for 'https://github.com': mictadlo
Password for 'https://mictadlo@github.com': 
To https://github.com/mictadlo/bioconda-recipes.git
 ! [rejected]            haslr -> haslr (fetch first)
error: failed to push some refs to 'https://github.com/mictadlo/bioconda-recipes.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
(base) debian@appdev:/mnt/OneTB/bioconda-recipes/recipes$ git pull
hint: Pulling without specifying how to reconcile divergent branches is
hint: discouraged. You can squelch this message by running one of the following
hint: commands sometime before your next pull:
hint: 
hint:   git config pull.rebase false  # merge (the default strategy)
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only
hint: 
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.

(base) debian@appdev:/mnt/OneTB/bioconda-recipes/recipes$ git pull haslr
hint: Pulling without specifying how to reconcile divergent branches is
hint: discouraged. You can squelch this message by running one of the following
hint: commands sometime before your next pull:
hint: 
hint:   git config pull.rebase false  # merge (the default strategy)
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only
hint: 
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: 'haslr' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
(base) debian@appdev:/mnt/OneTB/bioconda-recipes/recipes$ git checkout master
git pull upstream master
git push origin master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
hint: Pulling without specifying how to reconcile divergent branches is
hint: discouraged. You can squelch this message by running one of the following
hint: commands sometime before your next pull:
hint: 
hint:   git config pull.rebase false  # merge (the default strategy)
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only
hint: 
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: 'upstream' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Username for 'https://github.com': mictadlo
Password for 'https://mictadlo@github.com': 
Everything up-to-date

How can I fix it?

torek
  • 448,244
  • 59
  • 642
  • 775
user977828
  • 7,259
  • 16
  • 66
  • 117

1 Answers1

1

So all that seems to have happened is:

You said

git add haslr
git commit

Which is sort of weird because it seems like you have a folder called haslr which is the same as your branch name haslr. But whatever. Then:

git push

That failed because on the remote someone has made commits you don't have. Then:

git pull

That failed because you have no tracking set up so Git doesn't know what to do.

git pull haslr

That failed because it is meaningless. You should have said:

git pull origin haslr

But you didn't. So then you seem to have given up and said

git checkout master

Which worked but was kind of pointless. Then you did some totally irrelevant stuff, because master is not where you want to be. Basically you need to go back to haslr, pull properly (as I've shown you) and then push properly.

(Also your life would be a lot calmer if you did what Git advises you to do. For instance, you should configure your git config in a sensible way so as to silence those repeated warnings.)

matt
  • 515,959
  • 87
  • 875
  • 1,141