043_pull_and_fetch
======================================================================
There are 2 ways which you can use
when you bring data from remote repository to local repositories
They're git pull and git fetch
======================================================================
Create 2 local repositories (home and office)
which share same remote repository (repo)
======================================================================
Suppose this situation
where you push "tasks" into "repo" remote repository
and where you need to bring data from "repo" remote repository
In that situation, you can use "pull" or "fetch"
======================================================================
You generally can use "pull"
But when you need elaboration, you need to use "fetch"
======================================================================
# At dev/git/office master
vim f1.txt
a
b
c
d
e
d
git commit -am 6
# Upload your task onto remote repository
git push
======================================================================
# At dev/git/home master
git pull
When you perform "pull", you will see following
======================================================================
Let's see what internally happened
# --all: to see logs against all branches
# --oneline: to see logs in oneline
git log --decorate --all c
HEAD->master branch and origin/master branch point to same commit (6)
======================================================================
file you wrote just ago
name of file you edited just ago
commit you did just ago
======================================================================
./.git/refs/heads/master file
./.git/refs/remotes/origin/master file
They point same commit.
======================================================================
./.git/ORIG_HEAD file is pointing to
======================================================================
# At dev/git/office master
vim f1.txt
a
b
c
d
e
d
f
git commit -am 7
git push
======================================================================
# at dev/git/home master
git fetch
======================================================================
git log --decorate --all --oneline
master branch of local repository (HEAD->master) is pointing to "commit 6"
master branch of origin remote repository (origin/master) is pointing to "commit 7"
That is, step of remote repository (origin/master) is further
than local repository (HEAD->masster)
======================================================================
You downloaded following data
"commit 7"
file name
file contents
./.git/refs/remotes/origin/master is pointing to "commit 7"
======================================================================
On the other hand,
./.git/refs/heads/master is pointing to "commit 6"
======================================================================
What you have done so far with "fetch" is
that
1. you download data from remote repository to dev/git/home local repository
1. you also downloaded "commits" from remote repository
1. but you didn't apply those downloaded "commits"
to dev/git/home local repository yet
======================================================================
advantages:
1. you bring data from remote repositories
but you don't automatically perform "merge"
so, you can compare "status of dev/git/home local repository"
to "status of origin/master remote repository"
by using following commands
git log --decorate --all --oneline
HEAD means latest commit of HEAD of your local repository
git diff HEAD origin/master
# f is added in origin/master
======================================================================
Then, you can run "git merge origin/master"
to merge "origin/master" into master branch of dev/git/home local repository