Set your presentation theme:
Black (default) -
White -
League -
Sky -
Beige -
Simple
Serif -
Blood -
Night -
Moon -
Solarized
H:
by Jean Pierre Charalambos
Universidad Nacional de Colombia
Presentation best seen online
See also the source code
H:
- Introduction
- Getting started
- Git basics
- Git branching
- Github-based projects
- References
- Workshop
H:
- The problem
- Version control system types
- What's git?
- Why use git?
V:
working on a project comprising several source files
A presentationV:
working on a project comprising several source files
A bookV:
working on a project comprising several source files
Any other softwareV:
and wanna keep track of history
Why?
V:
To time travel...
V:
... in order to:
- Go back in time and check out a previous state
- Recover it undoing a mistake
- Explore it
- Make edits starting from it (creating a branched history)
- Come back to the present
- merge other branches
- (or do it the other way around)
V:
Conclusion
'Creativity' (as when writting a book, coding a program) is:
a non-linear iterative process of experimentation towards an open goal*
* no matter how you do it, a goal that can anytime be revised and/or broken up into accomplishable stages
V:
Local Version Control SystemsV:
centralized Version Control SystemsN:
Disadvantages:
- Remote nature of versioning commands
- Data corruption
V:
Distributed Version Control SystemsV:
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
V:
git
is British English slang meaning "unpleasant person"
I'm an egotistical bastard, and I name all my projects after myself. First 'Linux', now 'git' -- Torvalds
V:
- Private creativity affairs
- Team creativity affairs
V:
To safely keep track of some project sources sequence of commits (previous explicitly recorded states)
V:
Subversion-Style WorkflowN:
Works like subversion
V:
Integration Manager WorkflowN:
- The project maintainer pushes to their public repository
- A contributor clones that repository and makes changes
- The contributor pushes to their own public copy
- The contributor sends the maintainer an email asking them to pull changes
- The maintainer adds the contributor’s repo as a remote and merges locally
- The maintainer pushes merged changes to the main repository
V:
Dictator and Lieutenants WorkflowN:
- Regular developers work on their topic branch and rebase their work on top of master. The master branch is that of the reference directory to which the dictator pushes
- Lieutenants merge the developers' topic branches into their master branch
- The dictator merges the lieutenants' master branches into their master branch
- The dictator pushes their master to the reference repository so the other developers can rebase on it
V:
Pull requestsH:
- Recorded history
- File states
- First time setup
- Getting help
V:
Sequence of snapshotsV:
A file may be in one out of three 'states':
V:
Git project sectionsV:
Getting started: first time setup
$ git config --global user.name Falcao
$ git config --global user.email falcao@gmail.com
$ git config --list
V:
$ git help <command>
H:
- Getting a repository
- Recording changes
- Viewing the history
- Undoing things
- Working with remotes
V:
V:
From now on, I will be referring to the presentation itself git source code repository
V:
The lifecycle of the status of your filesV:
Checking the status of your files
$ git status
On branch gh-pages
Your branch is up-to-date with 'origin/gh-pages'.
nothing to commit, working directory clean
V:
Checking the status of your files
Suppose you edit the source.md
file:
$ git status
On branch gh-pages
Your branch is up-to-date with 'origin/gh-pages'.
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: source.md
no changes added to commit (use "git add" and/or "git commit -a")
V:
Viewing your staged and unstaged changes
To see what you've changed but not yet staged:
$ git diff
diff --git a/source.md b/source.md
index 02dd0b3..5891ca3 100644
--- a/source.md
+++ b/source.md
...
V:
Viewing your staged and unstaged changes
To see what you've staged that will go into your next commit
$ git diff --staged
V:
Checking the status of your files
Suppose you create a fig/lifecycle.png
file:
$ git status
On branch gh-pages
Your branch is up-to-date with 'origin/gh-pages'.
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: source.md
Untracked files:
(use "git add <file>..." to include in what will be committed)
fig/lifecycle.png
no changes added to commit (use "git add" and/or "git commit -a")
V:
git add fig/lifecycle.png
$ git status
On branch gh-pages
Your branch is up-to-date with 'origin/gh-pages'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: fig/lifecycle.png
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: source.md
V:
$ git commit -m 'life-cycle figure added'
[gh-pages fa1ffed] life-cycle figure added
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 fig/lifecycle.png
$ git status
On branch gh-pages
Your branch is ahead of 'origin/gh-pages' by 1 commit.
(use "git push" to publish your local commits)
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: source.md
no changes added to commit (use "git add" and/or "git commit -a")
V:
Instead of:
$ git add source.md
$ git commit -m 'source update'
you can do:
$ git commit -am 'source update'
$ git status
On branch gh-pages
Your branch is ahead of 'origin/gh-pages' by 2 commits.
(use "git push" to publish your local commits)
nothing to commit, working directory clean
V:
Adding the -a
option to the git commit
command makes Git automatically stage every file that is already tracked before doing the commit
V:
$ rm PROJECTS.md
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add/rm ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)
deleted: PROJECTS.md
no changes added to commit (use "git add" and/or "git commit -a")
V:
Remove it from your staging area and then commit (git rm
)
$ git rm PROJECTS.md
rm 'PROJECTS.md'
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD ..." to unstage)
deleted: PROJECTS.md
V:
$ git mv file_from file_to
$ git mv README.md README
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD ..." to unstage)
renamed: README.md -> README
$ mv README.md README
$ git rm README.md
$ git add README
V:
$ git log
commit b6545c874fdc622ecc35d28747cd2f7a0be268f2
Author: Jean Pierre Charalambos <nakednous@gmail.com>
Date: Fri Aug 28 11:28:14 2015 -0500
source update
commit fa1ffed1052dd9a0dc26b5211aadd0b93fdfb7c7
Author: Jean Pierre Charalambos <nakednous@gmail.com>
Date: Fri Aug 28 11:19:28 2015 -0500
life-cycle figure added
commit 4e65f72a195de0322fe943ed561a6e826d4b7991
Author: Jean Pierre Charalambos <nakednous@gmail.com>
Date: Thu Aug 27 19:24:56 2015 -0500
intro and getting started sections completed
V:
git log --stat
commit b6545c874fdc622ecc35d28747cd2f7a0be268f2
Author: Jean Pierre Charalambos <nakednous@gmail.com>
Date: Fri Aug 28 11:28:14 2015 -0500
source update
source.md | 195 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 194 insertions(+), 1 deletion(-)
commit fa1ffed1052dd9a0dc26b5211aadd0b93fdfb7c7
Author: Jean Pierre Charalambos <nakednous@gmail.com>
Date: Fri Aug 28 11:19:28 2015 -0500
life-cycle figure added
fig/lifecycle.png | Bin 0 -> 95510 bytes
1 file changed, 0 insertions(+), 0 deletions(-)
V:
$ git log --pretty=oneline
6545c874fdc622ecc35d28747cd2f7a0be268f2 source update
fa1ffed1052dd9a0dc26b5211aadd0b93fdfb7c7 life-cycle figure added
4e65f72a195de0322fe943ed561a6e826d4b7991 intro and getting started sections completed
V:
git log --pretty=format:"%h - %an, %ar : %s"
b6545c8 - Jean Pierre Charalambos, 5 hours ago : source update
fa1ffed - Jean Pierre Charalambos, 5 hours ago : life-cycle figure added
4e65f72 - Jean Pierre Charalambos, 21 hours ago : intro and getting started sections completed
V:
Useful options for git log --pretty=format
Option | Description output |
---|---|
%H | Commit hash |
%h | Abbreviated commit hash |
%T | Tree hash |
%t | Abbreviated tree hash |
%P | Parent hashes |
V:
Useful options for git log --pretty=format
Option | Description output |
---|---|
%p | Abbreviated parent hashes |
%an | Author name |
%ae | Author email |
%ad | Author date (format respects the --date=option) |
%ar | Author date, relative |
V:
Useful options for git log --pretty=format
Option | Description output |
---|---|
%cn | Committer name |
%ce | Committer email |
%cd | Committer date |
%cr | Committer date, relative |
%s | Subject |
V:
$ git log --pretty=format:"%h %s" --graph
* b6545c8 source update
* fa1ffed life-cycle figure added
* 4e65f72 intro and getting started sections completed
* 0c12be1 credits
* 72cbdb0 readme update
* 005edd9 readme update
* 83d5c80 adding figs
* 7639103 source update
* 9120f43 Merge branch 'master' of https://github.com/hakimel/reveal.js into gh-pages
|\
| * b390e66 add bower json #1067
| * 96bef35 Merge pull request #1287 from obilodeau/patch-1
| |\
| | * 98bdeae README: suggest decktape as an alternative for PDF rendering
| |/
| * 7225d84 Merge pull request #1260 from pierreozoux/master
| |\
V:
Common options to git log
Option | Description |
---|---|
-p | Show the patch introduced with each commit |
--stat | Show statistics for files modified in each commit |
--shortstat | Display only the changed/insertions/deletions line from the --stat command |
--name-only | Show the list of files modified after the commit information |
--name-status | Show the list of files affected with added/modified/deleted information as well |
V:
Common options to git log
Option | Description |
---|---|
--abbrev-commit | Show only the first few characters of the SHA-1 checksum instead of all 40 |
--relative-date | Display the date in a relative format (for example, 2 weeks ago) instead of using the full date format |
--graph | Display an ASCII graph of the branch and merge history beside the log output |
--pretty | Show commits in an alternate format. Options include oneline, short, full, fuller, and format (where you specify your own format) |
V:
$ git log --since=10.hours
commit b6545c874fdc622ecc35d28747cd2f7a0be268f2
Author: Jean Pierre Charalambos <nakednous@gmail.com>
Date: Fri Aug 28 11:28:14 2015 -0500
source update
commit fa1ffed1052dd9a0dc26b5211aadd0b93fdfb7c7
Author: Jean Pierre Charalambos <nakednous@gmail.com>
Date: Fri Aug 28 11:19:28 2015 -0500
life-cycle figure added
V:
Options to limit the output of git log
Option | Description |
---|---|
-(n) | Show only the last n commits |
--since, --after | Limit the commits to those made after the specified date |
--until, --before | Limit the commits to those made before the specified date |
V:
Options to limit the output of git log
Option | Description |
---|---|
--author | Only show commits in which the author entry matches the specified string |
--committer | Only show commits in which the committer entry matches the specified string |
--grep | Only show commits with a commit message containing the string |
-S | Only show commits adding or removing code matching the string |
V:
To change the commit message:
$ git commit --amend
To add a missing file:
$ git commit -m 'initial commit'
$ git add forgotten_file
$ git commit --amend
V:
$ git add source.md
$ git status
On branch gh-pages
Your branch is up-to-date with 'origin/gh-pages'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: source.md
$ git reset HEAD source.md
Unstaged changes after reset:
M source.md
V:
$ git status
On branch gh-pages
Your branch is up-to-date with 'origin/gh-pages'.
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: source.md
no changes added to commit (use "git add" and/or "git commit -a")
V:
Previously we got:
On branch gh-pages
Your branch is up-to-date with 'origin/gh-pages'.
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: source.md
no changes added to commit (use "git add" and/or "git commit -a")
V:
git checkout -- source.md
On branch gh-pages
Your branch is up-to-date with 'origin/gh-pages'.
nothing to commit, working directory clean
V:
As a rule of thumb: everything you commited can almost always be recovered.
git checkout -- [file]
is thus a dangerous command
V:
$ git clone https://github.com/objetos/git.git
$ git remote
origin
$ git remote -v
origin https://github.com/objetos/git.git (fetch)
origin https://github.com/objetos/git.git (push)
V:
git remote add [shortname] [url]
$ git remote add reveal https://github.com/hakimel/reveal.js.git
$ git remote -v
origin https://github.com/objetos/git.git (fetch)
origin https://github.com/objetos/git.git (push)
reveal https://github.com/hakimel/reveal.js.git (fetch)
reveal https://github.com/hakimel/reveal.js.git (push)
V:
Fetching and Pulling from Your Remotes
$ git fetch reveal
remote: Counting objects: 286, done.
remote: Total 286 (delta 118), reused 118 (delta 118), pack-reused 168
Receiving objects: 100% (286/286), 241.13 KiB | 348.00 KiB/s, done.
Resolving deltas: 100% (157/157), completed with 55 local objects.
From https://github.com/hakimel/reveal.js
* [new branch] dev -> reveal/dev
* [new branch] embed -> reveal/embed
* [new branch] flexbox -> reveal/flexbox
* [new branch] gh-pages -> reveal/gh-pages
* [new branch] master -> reveal/master
* [new tag] 0.3.0 -> 0.3.0
* [new tag] 1.0.0 -> 1.0.0
* [new tag] 1.1.0 -> 1.1.0
* [new tag] 1.2.0 -> 1.2.0
V:
Fetching and Pulling from Your Remotes
$ git checkout reveal/master
Note: checking out 'reveal/master'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at b390e66... add bower json #1067
$ git checkout master
Previous HEAD position was b390e66... add bower json #1067
Switched to branch 'master'`sh
V:
git push [remote-name] [branch-name]
$ git push origin gh-pages
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 6.54 KiB | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To https://github.com/objetos/git.git
b6545c8..d203838 gh-pages -> gh-pages
V:
git remote show [remote-name]
$ git remote show origin
* remote origin
Fetch URL: https://github.com/objetos/git.git
Push URL: https://github.com/objetos/git.git
HEAD branch: master
Remote branches:
gh-pages tracked
master tracked
Local branches configured for 'git pull':
gh-pages merges with remote gh-pages
master merges with remote master
Local refs configured for 'git push':
gh-pages pushes to gh-pages (up to date)
master pushes to master (up to date)
V:
git remote rename
$ git remote rename reveal rv
$ git remote
origin
rv
V:
git remote rm
$ git remote rm rv
$ git remote
origin
H:
V:
Working on this presentation
- Create a branch struct
- Do some work in that branch
V:
Working on this presentation
At this stage, you’d like to fix the formatting. You’ll do the following:
- Switch to your production branch
- Create a branch to do the formatting
- After it’s tested, merge the formatting branch
- Switch back to struct story and continue working
V:
Create the struct branch
$ git checkout -b struct
$ git status
On branch struct
nothing to commit, working tree clean
V:
Do some work in the struct branch
$ git checkout status
On branch struct
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: source.md
V:
Create the formatting branch
... but first finish work on struct branch
$ git checkout gh-pages
error: Your local changes to the following files would be overwritten by checkout:
source.md
Please commit your changes or stash them before you switch branches.
Aborting
$ git commit -am'more updated'
[struct 798cdbe] more updated
1 file changed, 51 insertions(+), 5 deletions(-)
V:
Create the formatting branch
$ git checkout gh-pages
Switched to branch 'gh-pages'
Your branch is up-to-date with 'origin/gh-pages'.
$ git checkout -b formatting
V:
Do some work in the formatting branch
$ git checkout status
On branch formatting
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: source.md
$ git commit -am'formatting done'
[formatting 587456f] formatting done
1 file changed, 68 insertions(+), 28 deletions(-)
V:
Merge the formatting branch onto the gh-pages
$ git checkout gh-pages
Switched to branch 'gh-pages'
$ git merge formatting
Updating b6b37b5..587456f
Fast-forward
source.md | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
1 file changed, 68 insertions(+), 28 deletions(-)
V:
Merge the struct branch onto the gh-pages
finish the work in the struct branch first...
$ git checkout struct
Switched to branch 'struct'
$ git commit -am'dev workflows notes'
[struct 1a13f5a] dev workflows notes
1 file changed, 72 insertions(+), 17 deletions(-)
V:
Merge the struct branch onto the gh-pages
... now merge
$ git checkout gh-pages
Switched to branch 'gh-pages'
Your branch is ahead of 'origin/gh-pages' by 1 commit.
(use "git push" to publish your local commits)
$ git merge struct
Auto-merging source.md
Merge made by the 'recursive' strategy.
source.md | 189 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 185 insertions(+), 4 deletions(-)
V:
final result
$ git log --graph --pretty=oneline
* 7bd70d280d32fcdde1490aac8a57bbd33fac3d76 more updates
* f70757509b3aa4d5d3e5e5cb4ade636461c4ca11 Merge branch 'struct' into gh-pages
|\
| * b35c44b4e739801041bb372b60ca7341511a6d5a dev workflows notes
| * 1a13f5a34929e1a3ba10772bd3aea327e1eb5f9f dev workflows notes
| * 5cedde5d9995b11f40007adb6d29b11d564b816c more updated
| * 798cdbe61f66bb3b1807a97168211ab5e2b89098 more updated
| * b3874fa1e8fae62647265bcc76b7f6ee613b15de contents added to the new branch
* | 587456f1b4d7817cfac4c8c7319cfb6cf30c78eb formatting done
|/
* b6b37b560dc39664bee74b60a6f6a63bc538e44a index and source updated to latest reveal
H:
N:
Pending: third party hosted option
H:
- Git site
- Pro Git book by Scott Chacon and Ben Straub and published by Apress, where most of the material found on this presentation has been hacked (when not noticed otherwise)
- Git reference quick most-used command reference
- Git tips & tricks
- Try Git online
- Further Git references
H:
- (level 1)
- Create a local Git repo to track some source files
- Create the program of your choice
- Begin to track your program source files with Git
- Commit some changes
- Use
git tool
and/orgit difftool
to study some changes
- (level 2)
- Create a branch to test an experimental feature
- Merge your
test branch
into yourmaster branch
- (level 3)
- Find new usages for
git commands
- Search for git-based projects such as Github pages
N:
Pending themes: Git on the server