Git Crash Course
-
Author
simone-soldateschi -
Category
Software
-
view
120 -
download
1
Embed Size (px)
description
Transcript of Git Crash Course

RACKSPACE® HOSTING | [email protected]
Agenda
● Presentation (20’)o Basic commandso Branching and mergingo Git repositories and sharing code
● Q&A (5’)● Quiz (5’)

RACKSPACE® HOSTING | [email protected]
Git setup
$ git config --global user.name "FOO BAR"$ git config --global user.email [email protected]

RACKSPACE® HOSTING | [email protected]
The very beginning
$ mkdir ccbb-git$ cd ccbb-git
$ lltotal 0drwxr-xr-x 2 simo6545 1604020879 68 Feb 1 09:01 ./drwxr-xr-x 117 simo6545 1604020879 3978 Feb 1 09:01 ../
local directory

RACKSPACE® HOSTING | [email protected]
Working directory
$ gitusage: 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
...

RACKSPACE® HOSTING | [email protected]
Working directory - poking around
$ echo 'The very beginning' > README
$ git statusfatal: Not a git repository (or any of the parent directories): .git
$ ls -latotal 8drwxr-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

RACKSPACE® HOSTING | [email protected]
Working directory - create repository
$ git initInitialized empty Git repository in /Users/simo6545/tmp/20140201-090152/.git/
$ lltotal 8drwxr-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

RACKSPACE® HOSTING | [email protected]
Working directory status$ git status# On branch master## Initial commit## Untracked files:# (use "git add <file>..." to include in what will be committed)## READMEnothing added to commit but untracked files present (use "git add" to track)

RACKSPACE® HOSTING | [email protected]
Staging area$ git status -s?? README
$ git add README
$ git status -sA README
stage changes

RACKSPACE® HOSTING | [email protected]
Staging area$ echo 'This is the second line.' >> README
$ git status -sAM README
$ git diffdiff --git a/README b/READMEindex 939d82f..9e92fed 100644--- a/README+++ b/README@@ -1 +1,2 @@ The very beginning+This is the second line.

RACKSPACE® HOSTING | [email protected]
Staging area
$ git add README
$ git status -sA README
Stage changes again:
$ git diff

RACKSPACE® HOSTING | [email protected]
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 logcommit 7c23e33b09b4863dbf59dbaec7bb023f7ff15c70Author: Simone Soldateschi <sim[email protected]>Date: Sat Feb 1 10:10:48 2014 +0000
First commit

RACKSPACE® HOSTING | [email protected]
Tagging$ git tag v0.1
$ git lg* 7c23e33 - (HEAD, tag: v0.1, master) First commit (63 minutes ago)
$ echo 'Still working...' >> README
$ git status -s M README
$ git add README$ git status -sM README

RACKSPACE® HOSTING | [email protected]
Tagging$ git commit -m 'Second commit'[master a0a8c4b] Second commit 1 file changed, 1 insertion(+)
$ git status -s
$ git lg* a0a8c4b - (HEAD, master) Second commit (6 seconds ago)* 7c23e33 - (tag: v0.1) First commit (67 minutes ago)
$ git tag v0.2
$ git lg* a0a8c4b - (HEAD, tag: v0.2, master) Second commit (6 seconds ago)* 7c23e33 - (tag: v0.1) First commit (67 minutes ago)

RACKSPACE® HOSTING | [email protected]
Agenda
● Presentation (20’)o Basic commandso Branching and mergingo Git repositories and sharing code
● Q&A (5’)● Quiz (5’)

RACKSPACE® HOSTING | [email protected]
Branching
$ git initInitialized empty Git repository in /Users/simo6545/tmp/20140201-090152/.git/$ echo 'The first line' > README$ git add README$ git commit -m 'C0'[master (root-commit) 38e3df8] C0 1 file changed, 1 insertion(+) create mode 100644 README$ echo 'The second line' >> README$ git add README$ git commit -m 'C1'[master 836e142] C1 1 file changed, 1 insertion(+)

RACKSPACE® HOSTING | [email protected]
Branching
$ echo 'Experimental line' >> README$ git add README$ git commit -m "C2"[experiment 18c3f30] C2 1 file changed, 1 insertion(+)

RACKSPACE® HOSTING | [email protected]
Merge conflict$ git merge experiment Auto-merging READMECONFLICT (content): Merge conflict in READMEAutomatic merge failed; fix conflicts and then commit the result.$ cat README The first lineThe second line<<<<<<< HEADThe third line=======Experimental lineAnother experimental lineThe last experimental line>>>>>>> experiment

RACKSPACE® HOSTING | [email protected]
Merge conflict
$ cat README The first lineThe second lineThe third lineExperimental lineAnother experimental lineThe last experimental line$ git add README $ git commit -m ‘C6’

RACKSPACE® HOSTING | [email protected]
RollbackCurrent content of README:
Look at repository logs:
Rollback:

RACKSPACE® HOSTING | [email protected]
Rollback
How does README look like?
What about repository logs?

RACKSPACE® HOSTING | [email protected]
Agenda
● Presentation (20’)o Basic commandso Branching and mergingo Git repositories and sharing code
● Q&A (5’)● Quiz (5’)

RACKSPACE® HOSTING | [email protected]
Git repos & sharing code
http://gitorious.org
http://gna.org/projects/savane/

RACKSPACE® HOSTING | [email protected]
Remote repository
$ git remote origin$ git remote -vorigin [email protected]:siso/ccbbgit.git (fetch)origin [email protected]:siso/ccbbgit.git (push)

RACKSPACE® HOSTING | [email protected]
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

RACKSPACE® HOSTING | [email protected]
Markdown
Markdown cheatsheethttps://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet

RACKSPACE® HOSTING | [email protected]
Remote repository - push$ git add README.md$ git commit -m 'first release'[master e0b1158] first release 1 file changed, 6 insertions(+)
$ git push origin master Counting objects: 5, done.Delta compression using up to 4 threads.Compressing objects: 100% (2/2), done.Writing objects: 100% (3/3), 464 bytes | 0 bytes/s, done.Total 3 (delta 0), reused 0 (delta 0)To [email protected]:siso/ccbbgit.git 5df3dad..e0b1158 master -> master

RACKSPACE® HOSTING | [email protected]

RACKSPACE® HOSTING | [email protected]
Git aliases
$ git config --global alias.b branch
$ git config --global alias.lg log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative
$ git config --global alias.serve !git daemon --reuseaddr --verbose --base-path=. --export-all ./.git
$ git config --global alias.st status st

RACKSPACE® HOSTING | [email protected]
Agenda
● Presentation (20’)o Basic commandso Branching and mergingo Git repositories and sharing code
● Q&A (5’)● Quiz (5’)

RACKSPACE® HOSTING | [email protected]

RACKSPACE® HOSTING | [email protected]
Agenda
● Presentation (20’)o Basic commandso Branching and mergingo Git repositories and sharing code
● Q&A (5’)● Quiz (5’)

RACKSPACE® HOSTING | [email protected]
References
Git SCMhttp://git-scm.com/
A Visual Git Referencehttp://marklodato.github.io/visual-git-guide/index-en.html
Git Workflowshttps://www.atlassian.com/git/workflows

RACKSPACE® HOSTING | [email protected]
Homework
● Replay examples● commit result to GitHub● send me a message

RACKSPACE® HOSTING | [email protected]