Skip to content

Instantly share code, notes, and snippets.

@gerjantd
Last active December 11, 2015 01:29
Show Gist options
  • Save gerjantd/4523597 to your computer and use it in GitHub Desktop.
Save gerjantd/4523597 to your computer and use it in GitHub Desktop.
Git: Git for Eclipse users worked example

Git for Eclipse users worked example

In first shell

$ mkdir example
$ cd example
$ git init
Initialized empty Git repository in /home/gerjan/example/.git/
$ echo "Hello, world" > README.txt
$ git commit
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	README.txt
nothing added to commit but untracked files present (use "git add" to track)
$ git add README.txt
$ git commit -m "Added README.txt"
[master (root-commit) 6a8170f] Added README.txt
1 file changed, 1 insertion(+)
create mode 100644 README.txt
$ echo "Hello, solar system" > README.txt 
$ git commit
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#	modified:   README.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
$ git commit -a -m "Updated README.txt"
[master 0ec35da] Updated README.txt
1 file changed, 1 insertion(+), 1 deletion(-)
$ git log --graph --oneline
* 0ec35da Updated README.txt
* 6a8170f Added README.txt
$ git checkout -b french 0b030bc
Switched to a new branch 'french'
$ cat README.txt 
Hello, world
$ echo "Bonjour, tout le monde" > README.txt 
$ git add README.txt
$ git commit -m "Ajouté README.txt"
[french 1917b07] Ajouté README.txt
1 file changed, 1 insertion(+), 1 deletion(-)
$ git log --graph --oneline
* 1917b07 Ajouté README.txt
* 6a8170f Added README.txt
$ git checkout -b web 0b030bc
Switched to a new branch 'web'
$ echo '<a href="http://git.eclipse.org">git.eclipse.org</a>' > index.html
$ git add index.html
$ git commit -m "Added homepage"
[web fb0f912] Added homepage
1 file changed, 1 insertion(+)
create mode 100644 index.html
$ git checkout master
Switched to branch 'master'
$ git branch
french
* master
web
$ git merge web
Merge made by the 'recursive' strategy.
index.html |    1 +
1 file changed, 1 insertion(+)
create mode 100644 index.html
$ git checkout french
Switched to branch 'french'
$ git merge web
Merge made by the 'recursive' strategy.
index.html |    1 +
1 file changed, 1 insertion(+)
create mode 100644 index.html
$ git log --graph --oneline
*   7071f5a Merge branch 'web' into french
|\  
| * fb0f912 Added homepage
* | 1917b07 Ajouté README.txt
|/  
* 6a8170f Added README.txt
$ git checkout master
Switched to branch 'master'
$ git log --graph --oneline
*   76f807c Merge branch 'web'
|\  
| * fb0f912 Added homepage
* | 0ec35da Updated README.txt
|/  
* 6a8170f Added README.txt

In other shell

$ mkdir other
$ cd other
$ git init
Initialized empty Git repository in /home/gerjan/other/.git/
$ ls -la
total 52
drwxrwxr-x  3 gerjan gerjan  4096 Jan 13 11:38 .
drwx------ 87 gerjan gerjan 40960 Jan 13 11:38 ..
drwxrwxr-x  7 gerjan gerjan  4096 Jan 13 11:38 .git
$ git config --bool core.bare true
$ ls -la
total 52
drwxrwxr-x  3 gerjan gerjan  4096 Jan 13 11:38 .
drwx------ 87 gerjan gerjan 40960 Jan 13 11:38 ..
drwxrwxr-x  7 gerjan gerjan  4096 Jan 13 11:38 .git

In first shell (~/example)

$ git remote add other /home/gerjan/other
$ git push other master
Counting objects: 11, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (11/11), 1003 bytes, done.
Total 11 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (11/11), done.
To /home/gerjan/other
* [new branch]      master -> master
$ git push --all other
Counting objects: 8, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 575 bytes, done.
Total 5 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (5/5), done.
To /home/gerjan/other
* [new branch]      french -> french
* [new branch]      web -> web

In other shell (~/other)

$ ls -la
total 52
drwxrwxr-x  3 gerjan gerjan  4096 Jan 13 11:38 .
drwx------ 87 gerjan gerjan 40960 Jan 13 11:38 ..
drwxrwxr-x  7 gerjan gerjan  4096 Jan 13 11:39 .git
$ git config --bool core.bare false
$ git branch
french
* master
web
$ git checkout web
Switched to branch 'web'
$ ls -la
total 76
drwxrwxr-x  3 gerjan gerjan  4096 Jan 13 11:40 .
drwx------ 87 gerjan gerjan 40960 Jan 13 11:38 ..
drwxrwxr-x  8 gerjan gerjan  4096 Jan 13 11:40 .git
-rw-rw-r--  1 gerjan gerjan    53 Jan 13 11:40 index.html
-rw-rw-r--  1 gerjan gerjan    13 Jan 13 11:40 README.txt
$ echo '<h1>Git rocks!</h1>' >> index.html 
$ git commit -a -m "Added Git rocks"
[web f6a988f] Added Git rocks
1 file changed, 1 insertion(+)

In first shell (~/example)

$ git branch
french
* master
web
$ git pull other web
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/gerjan/other
* branch            web        -> FETCH_HEAD
Merge made by the 'recursive' strategy.
index.html |    1 +
1 file changed, 1 insertion(+)
$ git log --graph --oneline
*   e33ddad Merge branch 'web' of /home/gerjan/other
|\  
| * f6a988f Added Git rocks
* |   76f807c Merge branch 'web'
|\ \  
| |/  
| * fb0f912 Added homepage
* | 0ec35da Updated README.txt
|/  
* 6a8170f Added README.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment