Este exemplo pode ajudar alguém:
Nota " origin" é meu apelido para remoto "O que há no Github"
Nota " mybranch" é meu apelido para minha ramificação "o que é local" que estou sincronizando com o github
- seu nome de ramificação é 'master' se você não criou 1. No entanto, estou usando o nome diferente mybranchpara mostrar onde o parâmetro do nome do ramo é usado.
Quais são exatamente meus repositórios remotos no github?
$ git remote -v
origin https://github.com/flipmcf/Playground.git (fetch)
origin https://github.com/flipmcf/Playground.git (push)
Adicione o "outro repositório github do mesmo código" - chamamos isso de fork:
$ git remote add someOtherRepo https://github.com/otherUser/Playground.git
$git remote -v
origin https://github.com/flipmcf/Playground.git (fetch)
origin https://github.com/flipmcf/Playground.git (push)
someOtherRepo https://github.com/otherUser/Playground.git (push)
someOtherRepo https://github.com/otherUser/Playground.git (fetch)
verifique se nosso repo local está atualizado:
$ git fetch
Mude algumas coisas localmente. digamos arquivo ./foo/bar.py
$ git status
# On branch mybranch
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: foo/bar.py
Revise minhas alterações não confirmadas
$ git diff mybranch
diff --git a/playground/foo/bar.py b/playground/foo/bar.py
index b4fb1be..516323b 100655
--- a/playground/foo/bar.py
+++ b/playground/foo/bar.py
@@ -1,27 +1,29 @@
- This line is wrong
+ This line is fixed now - yea!
+ And I added this line too.
Confirme localmente.
$ git commit foo/bar.py -m"I changed stuff"
[myfork 9f31ff7] I changed stuff
1 files changed, 2 insertions(+), 1 deletions(-)
Agora, sou diferente do meu controle remoto (no github)
$ git status
# On branch mybranch
# Your branch is ahead of 'origin/mybranch' by 1 commit.
#
nothing to commit (working directory clean)
Difere isso com o controle remoto - seu garfo: (isso geralmente é feito com git diff master origin)
$ git diff mybranch origin
diff --git a/playground/foo/bar.py b/playground/foo/bar.py
index 516323b..b4fb1be 100655
--- a/playground/foo/bar.py
+++ b/playground/foo/bar.py
@@ -1,27 +1,29 @@
- This line is wrong
+ This line is fixed now - yea!
+ And I added this line too.
(git push para aplicá-los ao controle remoto)
Como minha ramificação remota difere da ramificação mestre remota?
$ git diff origin/mybranch origin/master
Como meu material local difere do ramo mestre remoto?
$ git diff origin/master
Como minhas coisas diferem do garfo de outra pessoa, ramo principal do mesmo repositório?
$git diff mybranch someOtherRepo/master