Git branching, pulling and pushing etc.

CommandNew filesChanged filesDeleted files
Alice/> git init --template=""
Initialized empty Git repository in /home/rene/github/github/git-internals/repos/branch_2/Alice/.git/
snap no: 1
.git/HEAD
.git/config

Alice creates a file to store numbers …

Alice/> printf "one\ntow\nthree\nfour\nfife\nsix\nseven\neigth\nnine\n" > numbers.txt
snap no: 2

… adds it to the repository …

Alice/> git add numbers.txt
snap no: 3

… and commits it.

Alice/> git commit numbers.txt -m "+ numbers.txt"
[master (root-commit) 80e3760] + numbers.txt
 1 file changed, 9 insertions(+)
 create mode 100644 numbers.txt
snap no: 4
.git/COMMIT_EDITMSG
.git/logs/HEAD
.git/logs/refs/heads/master
.git/objects/80/e376080b1b1616daef27f1136347d377941fda [commit]
.git/objects/c8/52b721ba9dc9f99dd740246d787dd804a8e275 [tree]
.git/refs/heads/master

Unfortunately, Alice has made a few typos (tow instead of two, fife instead of five and eigth instead of eight)

Alice/> cat numbers.txt
one
tow
three
four
fife
six
seven
eigth
nine
snap no: 5

So, she creates a new branch to start fixing the typos

Alice/> git checkout -b fixTypo
Switched to a new branch 'fixTypo'
snap no: 6
.git/logs/refs/heads/fixTypo
.git/refs/heads/fixTypo
.git/HEAD
.git/logs/HEAD

Fix the first typo:

Alice/> sed -i s/tow/two/ numbers.txt
snap no: 7

Commit the fix:

Alice/> git commit numbers.txt -m "Fix typo: tow->two"
[fixTypo e0cea2c] Fix typo: tow->two
 1 file changed, 1 insertion(+), 1 deletion(-)
snap no: 8
.git/COMMIT_EDITMSG
.git/index
.git/logs/HEAD
.git/logs/refs/heads/fixTypo
.git/refs/heads/fixTypo

Immediately, Alice starts to fix the second typo:

Alice/> sed -i s/fife/five/ numbers.txt
snap no: 9

In the mean time, Bob clones Alice's repository.

Bob/> git clone --template="" /home/rene/github/github/git-internals/repos/branch_2/Alice .
Cloning into '.'...
done.

After cloning, he has received all objects that already are in Alice's repository.

snap no: 1
.git/packed-refs
.git/index
.git/HEAD
.git/config
.git/objects/4b/ac4b3e82a21e3bcbad355641126d833be1c192 [blob]
.git/objects/7f/b247e1c71f558f5c4ad9e53abb4eb98681bdd0 [blob]
.git/objects/80/e376080b1b1616daef27f1136347d377941fda [commit]
.git/objects/c8/52b721ba9dc9f99dd740246d787dd804a8e275 [tree]
.git/objects/ea/636a46f088b7ede4dfdb7f42cb670ff4b535a0 [tree]
.git/objects/e0/cea2c02ba508822c4f87af2084702a23198046 [commit]
.git/refs/heads/fixTypo
.git/refs/remotes/origin/HEAD
.git/logs/HEAD
.git/logs/refs/heads/fixTypo
.git/logs/refs/remotes/origin/HEAD
numbers.txt

Bob wants to inquire about available branches:

Bob/> git branch
* fixTypo

A little surprising, there is only the fixTypo branch and no master branch. This is (probably?) because he cloned from Alice's repository when it was in the fixTypo branch.

snap no: 2

So, in order to see the remote tracking branches, he uses the-r option:

Bob/> git branch -r
  origin/HEAD -> origin/fixTypo
  origin/fixTypo
  origin/master
snap no: 3

With the -a option, he sees all branches: remote tracking and local ones:

Bob/> git branch -a
* fixTypo
  remotes/origin/HEAD -> origin/fixTypo
  remotes/origin/fixTypo
  remotes/origin/master
snap no: 4

Examine the content of numbers.txt

Bob/> cat numbers.txt
one
two
three
four
fife
six
seven
eigth
nine

Bob sees the commited fix (two instead of tow) of Alice at the time of his cloning the repository.

snap no: 5

Bob wants to work on the master branch. Therefore, he creates it like so …

Bob/> git branch master origin/master
Branch master set up to track remote branch master from origin.
snap no: 6
.git/logs/refs/heads/master
.git/refs/heads/master
.git/config

… and switches to it:

Bob/> git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.

Note: Bob could have done the creation and switch to the new branch in one step: git checkout -b master origin/master.

snap no: 7
.git/HEAD
.git/index
.git/logs/HEAD
numbers.txt

The content of numbers.txt now has all three typos:

Bob/> cat numbers.txt
one
tow
three
four
fife
six
seven
eigth
nine
snap no: 8

In the mean time, Alice commits her second typo fix.

Alice/> git commit numbers.txt -m "Fix typo fife->five"
[fixTypo cc7b5b3] Fix typo fife->five
 1 file changed, 1 insertion(+), 1 deletion(-)
snap no: 10
.git/COMMIT_EDITMSG
.git/index
.git/logs/HEAD
.git/logs/refs/heads/fixTypo
.git/refs/heads/fixTypo

Bob, being on the master branch, adds 11 and 12 to numbers.txt:

Bob/> printf "eleven\ntwelve\n" >> numbers.txt
snap no: 9

Commit the changes:

Bob/> git commit numbers.txt -m "add 11 and 12"
[master f6ef2aa] add 11 and 12
 1 file changed, 2 insertions(+)
snap no: 10
.git/index
.git/logs/HEAD
.git/logs/refs/heads/master
.git/refs/heads/master
Bob/> git push origin master
To /home/rene/github/github/git-internals/repos/branch_2/Alice
   80e3760..f6ef2aa  master -> master
snap no: 11
.git/logs/refs/remotes/origin/master
.git/refs/remotes/origin/master

Bob's push also changes Alice's repository

snap no: 11
.git/logs/refs/heads/master
.git/refs/heads/master

He now pulls from Alice's repository:

Bob/> git pull
From /home/rene/github/github/git-internals/repos/branch_2/Alice
   e0cea2c..cc7b5b3  fixTypo    -> origin/fixTypo
Already up-to-date.

Note: it pulls the commit object of Alice's latest typo fix, but it does not update .git/refs/heads/fixTypo!

snap no: 12
.git/FETCH_HEAD
.git/ORIG_HEAD
.git/logs/refs/remotes/origin/fixTypo
.git/objects/64/516406f1da1f62195e0eb8a7d26b3a8bbf1940 [tree]
.git/objects/b8/0b8495d92c247d359aa89393613d1801bf3a94 [blob]
.git/objects/cc/7b5b38a516ea85f4711d1d28fa9eba5bea62d4 [commit]
.git/refs/remotes/origin/fixTypo

Bob checks out the fixTypo branch.

Bob/> git checkout fixTypo
Switched to branch 'fixTypo'
Your branch is behind 'origin/fixTypo' by 1 commit, and can be fast-forwarded.
  (use "git pull" to update your local branch)

He would be mistaken if he believed that he now has Alice's latest fix. Note git's warning Your branch is behind 'origin/fixTypo' by 1 commit…

snap no: 13
.git/HEAD
.git/index
.git/logs/HEAD
numbers.txt

Bob does not according to git's recommendation to execute git pull again…

Bob/> cat numbers.txt
one
two
three
four
fife
six
seven
eigth
nine

… so he still sees fife instead of the corrected five.

snap no: 14

He now does execute git pull

Bob/> git pull
Updating e0cea2c..cc7b5b3
Fast-forward
 numbers.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

… which updates .git/refs/heads/fixTypo. Note, that the command does not pull new objects into Bob's repository.

snap no: 15
.git/FETCH_HEAD
.git/ORIG_HEAD
.git/index
.git/logs/HEAD
.git/logs/refs/heads/fixTypo
.git/refs/heads/fixTypo
numbers.txt

Showing the content of the file:

Bob/> cat numbers.txt
one
two
three
four
five
six
seven
eigth
nine

This time, the file does contain Alice's correction.

snap no: 16

In the mean time, Alice checks out the master branch.

Alice/> git checkout master
Switched to branch 'master'

Note, git does not say anything about the branch being behind.

snap no: 12
.git/HEAD
.git/index
.git/logs/HEAD
numbers.txt

So, she sees Bob's addition of eleven and twelve.

Alice/> cat numbers.txt
one
tow
three
four
fife
six
seven
eigth
nine
eleven
twelve
snap no: 13