-
Notifications
You must be signed in to change notification settings - Fork 1
Pull branches
Before committing anything on this clone, let's play with our identity. with this clone we will simulate an other user. Previously we have seen how to set up a user name and e-mail (How to use git). We did it globally for all our repos, using git config --global. If you leave out the --global from it, the changes to the git configuration are just local to the local repo.
ben@GregoryHouse:~/tmp/testRepo-clone (experimental)$ git config user.name "Alice"
ben@GregoryHouse:~/tmp/testRepo-clone (experimental)$ git config user.email "alice@some_Server.net"Now we can play a bit!
ben@GregoryHouse:~/tmp/testRepo-clone (experimental)$ git config user.name "Alice"
ben@GregoryHouse:~/tmp/testRepo-clone (experimental)$ git config user.email "alice@some_Server.net"
ben@GregoryHouse:~/tmp/testRepo-clone (experimental)$ cd ../testRepo
ben@GregoryHouse:~/tmp/testRepo (experimental)$ gvim README
ben@GregoryHouse:~/tmp/testRepo (experimental)$ git commit -a -m "improvement"
[experimental c3df0e6] improvement
1 file changed, 1 insertion(+), 1 deletion(-)
ben@GregoryHouse:~/tmp/testRepo (experimental)$ cd ../testRepo-clone/Ok, we just committed another change on the repo owned by Ben. And we are back in the clone owned by Alice. In order to see the changes, we have to fetch them.Here you will discover that remote branches are not quite like local branches.
- First let's get the changes:
ben@GregoryHouse:~/tmp/testRepo-clone (experimental)$ git fetch origin
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From /home/ben/tmp/testRepo
16ff837..c3df0e6 experimental -> origin/experimental
ben@GregoryHouse:~/tmp/testRepo-clone (experimental)$ git log
commit 16ff83709eabef0444acfdda0fd9f9ca63905134
Author: Benoît Bleuzé <benoit.bleuze@gmail.com>
Date: Fri Aug 24 01:48:15 2012 +0200
added line in experimental branch
commit c6c55668158d872f39861a4620325f059938f452
Author: Benoît Bleuzé <benoit.bleuze@gmail.com>
Date: Thu Aug 23 07:25:19 2012 +0200
Add .gitignore, add a line to README
commit 4a9debafe19cd53dc9fb484c6df419c1e9344a6e
Author: Benoît Bleuzé <benoit.bleuze@gmail.com>
Date: Thu Aug 23 07:15:01 2012 +0200
First commit: add README- But, but but... the changes made in Ben's experimental branch are not here!? In fact they are in the local archive of the remote branch. The branch named remotes/origin/experimental (that you can also call origin/experimental). Let's check this information:
ben@GregoryHouse:~/tmp/testRepo-clone (experimental)$ git checkout origin/experimental
Note: checking out 'origin/experimental'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at c3df0e6... improvement
ben@GregoryHouse:~/tmp/testRepo-clone ((c3df0e6...))$ git log --oneline
c3df0e6 improvement
16ff837 added line in experimental branch
c6c5566 Add .gitignore, add a line to README
4a9deba First commit: add README- Indeed 2 interessant element:
- Git warns us we are in a detached head, so not in a real branch where you can commit.
- The changes have been transferred over.
*what is needed is to
git mergeour local archive of the remote branch with our local working branch it.
ben@GregoryHouse:~/tmp/testRepo-clone ((c3df0e6...))$ git checkout experimental
Previous HEAD position was c3df0e6... improvement
Switched to branch 'experimental'
Your branch is behind 'origin/experimental' by 1 commit, and can be fast-forwarded.
ben@GregoryHouse:~/tmp/testRepo-clone (experimental)$ git merge origin/experimental
Updating 16ff837..c3df0e6
Fast-forward
README | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
ben@GregoryHouse:~/tmp/testRepo-clone (experimental)$ git log --oneline
c3df0e6 improvement
16ff837 added line in experimental branch
c6c5566 Add .gitignore, add a line to README
4a9deba First commit: add README-
Once again git is nice enough to tell us we have some non-merged changes, and when we merge them, it tells us what were the changes when it replayed the history of the remote onto our local copy. You will have noiticed that we went forward from commit 16ff837... to c3df0e6...
-
git is for lazy people, so there is a shortcut for these two operations:
git fetch origin; git merge origin/branch_nameis the same asgit pull. pull does fetch + merge. -
We just did our first pull! This was easy there were no conflict. But we will see how to deal with them later...
Jump to Multiple remote repositories