The document is a presentation on Git basics that covers:
- Setting up Git with configuration
- The three main states that code can be in: working directory, staging area, committed
- Common commands like add, commit, status
- Branching and merging code along with resolving conflicts
- Using remote repositories and sharing code through cloning, pulling and pushing changes.
4. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
The very beginning
$ mkdir ccbb-git
$ cd ccbb-git
$ ll
total 0
drwxr-xr-x 2 simo6545 1604020879 68 Feb 1 09:01 ./
drwxr-xr-x 117 simo6545 1604020879 3978 Feb 1 09:01 ../
local directory
5. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Working directory
$ git
usage: git [--version] [--help] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-
path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
The most commonly used git commands are:
add Add file contents to the index
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches
...
6. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Working directory - poking around
$ echo 'The very beginning' > README
$ git status
fatal: Not a git repository (or any of the parent directories): .git
$ ls -la
total 8
drwxr-xr-x 3 simo6545 1604020879 102 Feb 1 09:28 .
drwxr-xr-x 117 simo6545 1604020879 3978 Feb 1 09:01 ..
-rw-r--r-- 1 simo6545 1604020879 19 Feb 1 09:28 README
7. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Working directory - create repository
$ git init
Initialized empty Git repository in /Users/simo6545/tmp/20140201-090152/.git/
$ ll
total 8
drwxr-xr-x 4 simo6545 1604020879 136 Feb 1 09:38 ./
drwxr-xr-x 117 simo6545 1604020879 3978 Feb 1 09:01 ../
drwxr-xr-x 9 simo6545 1604020879 306 Feb 1 09:39 .git/
-rw-r--r-- 1 simo6545 1604020879 19 Feb 1 09:28 README
working directory
8. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Working directory status
$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# README
nothing added to commit but untracked files present (use "git add" to track)
9. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Staging area
$ git status -s
?? README
$ git add README
$ git status -s
A README
stage changes
10. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Staging area
$ echo 'This is the second line.' >> README
$ git status -s
AM README
$ git diff
diff --git a/README b/README
index 939d82f..9e92fed 100644
--- a/README
+++ b/README
@@ -1 +1,2 @@
The very beginning
+This is the second line.
11. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Staging area
$ git add README
$ git status -s
A README
Stage changes again:
$ git diff
12. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Commit to Git repository
$ git commit -m 'First commit'
[master (root-commit) 7c23e33] First commit
1 file changed, 2 insertions(+)
create mode 100644 README
$ git log
commit 7c23e33b09b4863dbf59dbaec7bb023f7ff15c70
Author: Simone Soldateschi <simone.soldateschi@gmail.com>
Date: Sat Feb 1 10:10:48 2014 +0000
First commit
13. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Recap - The three states
28. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Merge conflict
$ git merge experiment
Auto-merging README
CONFLICT (content): Merge conflict in README
Automatic merge failed; fix conflicts and then commit the result.
$ cat README
The first line
The second line
<<<<<<< HEAD
The third line
=======
Experimental line
Another experimental line
The last experimental line
>>>>>>> experiment
29. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Merge conflict
$ cat README
The first line
The second line
The third line
Experimental line
Another experimental line
The last experimental line
$ git add README
$ git commit -m ‘C6’
30. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Rollback
Current content of README:
Look at repository logs:
Rollback:
31. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Rollback
How does README look like?
What about repository logs?
41. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
pull
do stuff
push
42. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Remote repository - README.md
$ cat > README.md << EOF
# Git Crash Course - Brown Bag
## Paragraph 1
* **Lorem ipsum dolor sit amet**, consectetur adipiscing elit. Donec tempor justo
vitae nisi condimentum, id lobortis turpis tincidunt.
## Paragraph 2
* Duis egestas arcu quis elit posuere, vel iaculis lacus lobortis. Duis ultricies
sem in diam facilisis, eget blandit mi rutrum.
EOF