Erro ao enviar arquivos para o GitHub

Alguém poderia me explicar este erro:

yuri@MintOS ~/Modelos/Projeto Programming/Project $ git push origin master
Username for 'https://github.com': yuriProgramador
Password for 'https://yuriProgramador@github.com': 
To https://github.com/yuriProgramador/web5Presentation.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/yuriProgramador/web5Presentation.git'
dica: Updates were rejected because the remote contains work that you do
dica: not have locally. This is usually caused by another repository pushing
dica: to the same ref. You may want to first integrate the remote changes
dica: (e.g., 'git pull ...') before pushing again.
dica: See the 'Note about fast-forwards' in 'git push --help' for details.
1 curtida

Você tá tentando enviar como ? pelo eclipse, android studio ?

1 curtida

Pelo terminal linux

Eu já tinha usado antes o git com o GitHub e eu configurei com chaves SSH, mas agora estou tentando enviar por protocolo HTTPS, será que é as chaves que está dando problemas?

Você está tentando dar um push, mas teu repositório local não está sincronizado com o remoto.

Você tem que fazer o merge dos teus commits com os que foram pro repositório depois de você clona-lo.

Por exemplo, imagine que o repositório tem esses commits:

Remoto: A -> B -> C

Você fez o clone, tem uma cópia exatamente igual na tua máquina:

Local: A -> B -> C

Você fez um commit novo, o local ficou assim:

Local: A -> B -> C -> D

Nesse meio tempo, enquanto você fez o commit D, alguém deu um commit no remoto, deixando-o assim:

Remoto: A -> B -> C -> E

Você agora está tentando dar push no teu A -> B -> C -> D , e o remoto está diferente. Existe um conflito, porque na tua máquina, de C vai para D, e na do servidor, de C vai para E. Você precisa dar merge nos commits D e E.

Primeiro passo:

git fetch

Esse comando vai baixar o conteúdo do repositório local para tua máquina. Se você quiser ver as branchs, digita assim:

git branch -va

Vai aparecer a branch remota, algo mais ou menos assim: remotes/<nome_do_repositorio>/<nome_da_branch>.

Na tua branch local, você vai fazer isso:

git merge remotes/<nome_do_repositorio>/<nome_da_branch>

Por exemplo: Se o teu repositório remoto é apelidado de origin e a branch é a master, você vai fazer algo assim

git merge remotes/origin/master

Certo? Se não exisitrem conflitos, vai ser de boa. É só digitar git push para subir as mudanças para o repositório remoto. Caso hajam conflitos, você vai ter que resolve-los e terminar o commit do merge, podendo então fazer o push.

Outra maneira de fazer isso, é utilizando git pull. O pull nada mais é do que fetch e uma tentativa de merge. É só um atalho para você. O pull vai fazer o que eu disse pra você fazer nesse passos anteriores.

1 curtida

Veja o que apareceu:

yuri@MintOS ~/Modelos/Projeto Programming/Project $ git fetch
warning: no common commits
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/yuriProgramador/web5Presentation
 * [new branch]      master     -> origin/master
yuri@MintOS ~/Modelos/Projeto Programming/Project $ ls
a.txt   d.txt   feature7.txt  fk.txt  g.txt      html.txt
b.txt   ee.txt  feature8.txt  f.txt   html2.txt  igor.txt
c2.txt  e.txt   ff.txt        gg.txt  html3.txt  yuri.txt
yuri@MintOS ~/Modelos/Projeto Programming/Project $ git merge remotes/Project/master
merge: remotes/Project/master - not something we can merge
yuri@MintOS ~/Modelos/Projeto Programming/Project $ git merge remotes/origin/master
fatal: refusing to merge unrelated histories

Tenta só git pull, mais fácil.

Um merge só pode acontecer entre branches que têm um commit ancestral em comum. Até dá para juntar duas branches sem um ancestral comum, mas é um pouco mais trabalhoso.

Não sei te dizer porque esse erro está acontecendo, teria que dar uma olhada no grafo de commits. Cola aqui se não for muito grande:

git log --oneline --decorate --graph --all
1 curtida

Veja:

* ca7e6e0 (HEAD -> master) Added h.txt
*   c78c465 Fixed feature1 content
|\  
| * 8b68dd9 gg.txt
| * 2341094 gg.txt
* | 8e48824 gg.txt
|/  
*   24c025e Merge branch 'feature7'
|\  
| * 3a8efca feature7
* | c5d8751 feature8.txt
|/  
*-.   c74c82a Merge branches 'feature1' and 'feature2'
|\ \  
| | * 894ba21 html2.txt
| * | 95ed10c html.txt
| |/  
* | 6c8f8a4 html3.txt
|/  
* 1aa8574 fMaster content in master
*   5eef2e5 igor.txt in master branch altered changed
|\  
| * b5e5c5f igor.txt in feature6 branch
* | f342164 igor.txt in master branch
|/  
* 2ec806b yuri.txt
*   1575e3b Merge branch 'feature4'
|\  
| * fffc05f ff.txt
* | a7ad644 ee.txt
|/  
*   c47cb8d merge g.txt
|\  
| * ffd9575 g.txt
* | cc8bb82 g.txt
|/  
*   228241f Merge branch 'feature2'
|\  
| * a692b7b e.txt
* | fe504e6 f.txt
|/  
* 84e9a22 d.txt
* 45426e6 c2.txt
* 336c4cf c.txt alter
* 5d333e4 c.txt
* 2d06600 a.txt e b.txt
* 716cf31 (origin/master) Initial commit

Só que antes de eu postar essa dúvida aqui, o meu código estava com um stash, depois eu fiz isso: git stash drop stash@{0}
E parte do grafo estava assim:

* 716cf31 (origin/master) Initial commit
*   f841942 (refs/stash) WIP on feature5: c78c465 Fixed feature1 content
|\  
| * 0638f5f index on feature5: c78c465 Fixed feature1 content
|/  
*   c78c465 (HEAD -> master) Fixed feature1 content
|\  
| * 8b68dd9 gg.txt
| * 2341094 gg.txt
* | 8e48824 gg.txt
|/  
*   24c025e Merge branch 'feature7'
|\  
| * 3a8efca feature7
* | c5d8751 feature8.txt
|/  
*-.   c74c82a Merge branches 'feature1' and 'feature2'
|\ \  
| | * 894ba21 html2.txt
| * | 95ed10c html.txt
| |/  
* | 6c8f8a4 html3.txt
|/  
* 1aa8574 fMaster content in master
*   5eef2e5 igor.txt in master branch altered changed
|\  
| * b5e5c5f igor.txt in feature6 branch
* | f342164 igor.txt in master branch
|/  
* 2ec806b yuri.txt
*   1575e3b Merge branch 'feature4'
|\  
| * fffc05f ff.txt
* | a7ad644 ee.txt
|/  
*   c47cb8d merge g.txt

Mas continua a mesma coisa

Ahh e quando faço git pull ele me retorna isso:

There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master

Tenta

git pull origin master
1 curtida
yuri@MintOS ~/Modelos/Projeto Programming/Project $ git pull origin master
From https://github.com/yuriProgramador/web5Presentation
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

Observando o grafo, dá pra ver que teria como fazer um fast-forward da origin/master pra tua master local. Sinceramente não sei porque isso tá acontecendo. No erro que você colou, ele tá reclamando que tua branch atual não tem uma upstream. Pra corrigir isso, você pode tentar fazer assim:

git push -u origin master
1 curtida
yuri@MintOS ~/Modelos/Projeto Programming/Project $ git push -u origin master
Username for 'https://github.com': yuriProgramador
Password for 'https://yuriProgramador@github.com': 
To https://github.com/yuriProgramador/web5Presentation
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/yuriProgramador/web5Presentation'
dica: Updates were rejected because the tip of your current branch is behind
dica: its remote counterpart. Integrate the remote changes (e.g.
dica: 'git pull ...') before pushing again.
dica: See the 'Note about fast-forwards' in 'git push --help' for details.

Ele pede usuário e senha

git fetch origin
git merge origin master
1 curtida
yuri@MintOS ~/Modelos/Projeto Programming/Project $ git fetch origin 
yuri@MintOS ~/Modelos/Projeto Programming/Project $ git merge origin master
merge: origin - not something we can merge

Dá esse erro porque origin não é uma branch. Tenta fazer que nem no começo, só que sem o remotes:

git merge origin/master

Não entendi bem, mas é pra fazer assim?
O resultado foi isto:

    yuri@MintOS ~/Modelos/Projeto Programming/Project $ git merge origin/master
    fatal: refusing to merge unrelated histories