Design with the user

27 November 2014

1. Version control systems

2. Git

1. Version control systems

Producing Open Source Software

Source: http://producingoss.com/

A collaborative process: an example

Source: http://reprap.org/wiki/Mendel

A collaborative process: A spool for the RepRap Mendel

Source: http://www.thingiverse.com/thing:3866

A real example, from Thingiverse

Source: http://www.thingiverse.com/

A collaborative process: A spool for the RepRap Mendel (01)

Source: http://www.thingiverse.com/thing:3866

A collaborative process: A spool for the RepRap Mendel (02)

Source: http://www.thingiverse.com/thing:3962

A collaborative process: A spool for the RepRap Mendel (03)

Source: http://www.thingiverse.com/thing:4337

A centralized version control system

A centralized version control system: workflow

A centralized version control system: workflow

A centralized version control system: workflow

Subversion (SVN)

Source: http://subversion.apache.org/

Subversion (SVN): a free book

Source: Pilato, C. M., Collins-Sussman, B., & Fitzpatrick, B. W. (2008). Version control with Subversion. Sebastopol, CA: O’Reilly Media. Retrieved from http://svnbook.red-bean.com/

Versioning model: the problem

Source: Pilato, C. M., Collins-Sussman, B., & Fitzpatrick, B. W. (2008). Version control with Subversion. Sebastopol, CA: O’Reilly Media. Retrieved from http://svnbook.red-bean.com/

Versioning model: The lock-modify-unlock solution

Source: Pilato, C. M., Collins-Sussman, B., & Fitzpatrick, B. W. (2008). Version control with Subversion. Sebastopol, CA: O’Reilly Media. Retrieved from http://svnbook.red-bean.com/

Versioning model: The copy-modify-merge solution

Source: Pilato, C. M., Collins-Sussman, B., & Fitzpatrick, B. W. (2008). Version control with Subversion. Sebastopol, CA: O’Reilly Media. Retrieved from http://svnbook.red-bean.com/

Versioning model: The copy-modify-merge solution

Source: Pilato, C. M., Collins-Sussman, B., & Fitzpatrick, B. W. (2008). Version control with Subversion. Sebastopol, CA: O’Reilly Media. Retrieved from http://svnbook.red-bean.com/

2. Git

Git

Source: http://git-scm.com/

Git

Source: http://youtu.be/hKfo0OXc1BI

A distributed version control system

A distributed version control system: workflow

A distributed version control system: workflow

A distributed version control system: workflow

A distributed version control system: workflow

A distributed version control system: workflow

Git: a good free book

Source: Chacon, S. (2009). Pro Git. Berkeley, CA; New York: Apress ; Distributed to the Book trade worldwide by Springer-Verlag. Retrieved from http://git-scm.com/book

Git: a better but not free book

Source: Loeliger, J., & McCullough, M. (2012). Version Control with Git: Powerful tools and techniques for collaborative software development (2 edition.). O’Reilly Media.

Git: a quick guide

Source: http://rogerdudler.github.io/git-guide/

Git: a guided tour

Source: http://gitimmersion.com/

Git: an interactive cheatsheet

Source: http://ndpsoftware.com/git-cheatsheet.html

VCS: history of differences (deltas)

Source: Chacon, S. (2009). Pro Git. Berkeley, CA; New York: Apress ; Distributed to the Book trade worldwide by Springer-Verlag. Retrieved from http://git-scm.com/book

Git: history of a file system

Source: Chacon, S. (2009). Pro Git. Berkeley, CA; New York: Apress ; Distributed to the Book trade worldwide by Springer-Verlag. Retrieved from http://git-scm.com/book

Git: architecture

Source: Chacon, S. (2009). Pro Git. Berkeley, CA; New York: Apress ; Distributed to the Book trade worldwide by Springer-Verlag. Retrieved from http://git-scm.com/book

Git: workflow of a file

Source: Chacon, S. (2009). Pro Git. Berkeley, CA; New York: Apress ; Distributed to the Book trade worldwide by Springer-Verlag. Retrieved from http://git-scm.com/book

Open the Terminal (Mac)

Open the Git Bash (Win)

Source: https://help.github.com/articles/set-up-git#platform-windows

The command line, some notes (01)


					pwd #Print current directory
					

					cd <directory name> #Enter into a directory
					

					cd .. #Exit from the directory by going to the parent directory
					

					ls #List the files of the current directory
					

					ls -l #List the files  of the current directory, with details
					

					ls -la #List the files with hidden files and folders
					

The command line, some notes (02)


					mkdir <directory name> #Make a directory
					

					rm -r <directory name> #Erase a directory and its contents
					

					touch <file name> #Make an empty file
					

					vim <file name> #Edit an empty file.
					

"I" for editing and then "Esc", ":w" for saving, ":q" for quitting


					rm <file name> #Erase a file
					

					mv <file name> <where to move it> #Move or rename a file
					

					cp <file name> <where to copy it> #Copy a file
					

Git: configuration

				
					git config --global user.name "Name Surname" #Configure your name
					
				
					git config --global user.email "email@email.com" #Configure your e-mail
					

					git config --global color.ui auto #Color the output
					

Download P4Merge (Win, Mac, Linux)

Source: http://www.perforce.com/product/components/perforce-visual-merge-and-diff-tools

Download P4Merge (Win, Mac, Linux)

Source: http://www.perforce.com/downloads/Perforce/20-User#10

Install only P4Merge (Win, Mac, Linux)

Configure Git to use P4Merge (on Mac)


					git config --global merge.tool p4mergetool
					

					git config --global mergetool.p4mergetool.cmd \
"/Applications/p4merge.app/Contents/Resources/launchp4merge \$PWD/\$BASE \$PWD/\$REMOTE \$PWD/\$LOCAL \$PWD/\$MERGED"
					

					git config --global mergetool.p4mergetool.trustExitCode false
					

					git config --global mergetool.keepBackup false
					

					git config --global diff.tool p4mergetool
					

					git config --global difftool.p4mergetool.cmd \
"/Applications/p4merge.app/Contents/Resources/launchp4merge \$LOCAL \$REMOTE"
					

Source: https://gist.github.com/tony4d/3454372

Configure Git to use P4Merge (on Win)


					git config --global merge.tool p4mergetool
					

					git config --global mergetool.p4merge.cmd 'p4merge.exe \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"'
					

					git config --global mergetool.p4mergetool.trustExitCode false
					

					git config --global mergetool.keepBackup false
					

					git config --global diff.tool p4mergetool
					

					git config --global difftool.p4merge.cmd 'p4merge.exe \"$LOCAL\" \"$REMOTE\"'
					

Source: https://gist.github.com/daredude/1350855

Lunch time! Questions?

See you at 13:00

Git: workflow of a file

Source: Chacon, S. (2009). Pro Git. Berkeley, CA; New York: Apress ; Distributed to the Book trade worldwide by Springer-Verlag. Retrieved from http://git-scm.com/book

Git: workflow

Source: http://commons.wikimedia.org/wiki/Category:Git

Using Git locally (01): start


					cd <directory name> #Enter into the project directory
					

					git init #Start local repository
					

					git status #Get status of the working directory/stage
					

					git add <file name> #Add a file to the stage
					

					git add . #Add all files from current directory to the stage
					

					git add -u #Update (add) all files already being tracked
					

					git commit -m "messagetext" #Commit changes with a message
					

Git: commit history

Source: Chacon, S. (2009). Pro Git. Berkeley, CA; New York: Apress ; Distributed to the Book trade worldwide by Springer-Verlag. Retrieved from http://git-scm.com/book

Exercise: 01

Create a local repository, and add + commit your bio file written in Markdown (more info here and here).

Using Git locally (02): modifications and history


					git rm <file name> #Erase a file within Git
					

					git rm -f <file name> #Erase a file from the index from Git 
					

					git mv <file name> <wheretomove> #Move a file within Git
					

					git log #Commit history in the command line
					

					gitk #Commit history in a separate window
					

					git diff-tree --no-commit-id --name-only -r <commithash> #Changed files of a commit
					

					git ls-tree --name-only <commithash> #All files of a commit
					

Exercise: 02

Rename your bio file name.surname.md.

Using Git locally (04): undoing


					01: git commit -m "initial commit"
					

					02: git add <forgotten file>
					

					git commit --amend #Replace last commit with added/removed files
					

					git reset HEAD <file name> #Unstage a staged file
					

					git checkout -- <file name> #Overwrite a file with last commit version
					

More information: http://git-scm.com/book/en/Git-Basics-Undoing-Things

Using Git remotely (05): Remotes (A)


					git clone <link to repository> #Clone a remote repo locally
					

					git add remote <name> <link to repo> #Add a remote repository with a name
					

					git remote -v #View current remotes
					

					git remote rm <name of the remote> #Remove a remote repo
					

					git push <name of the remote> #Push local changes to remote
					

					git pull <name of the remote> #Get+merge new version from remote
					

					...
					

Exercise: 03

Create a repository on GitHub, and add its remote to your local repository, and push your bio.

Git: Branching

Source: Chacon, S. (2009). Pro Git. Berkeley, CA; New York: Apress ; Distributed to the Book trade worldwide by Springer-Verlag. Retrieved from http://git-scm.com/book

Git: Branching

Source: Chacon, S. (2009). Pro Git. Berkeley, CA; New York: Apress ; Distributed to the Book trade worldwide by Springer-Verlag. Retrieved from http://git-scm.com/book

Git: Merging

Source: Chacon, S. (2009). Pro Git. Berkeley, CA; New York: Apress ; Distributed to the Book trade worldwide by Springer-Verlag. Retrieved from http://git-scm.com/book

Using Git locally (06): branches


					git branch <name of the branch> #Create a local branch
					

					git push <name of the remote> <name of the branch> #Push branch to remote
					

					git checkout <name of the branch> #Switch to another branch
					

					git checkout master #Go back to master branch
					

					git diff <name of the branch> master #Diff branches before merging
					

					git merge <name of the branch> #Merge the branch with current branch
					

					git branch -d <name of the branch> #Delete a local branch
					

					git push origin :<name of the branch> #Delete a remote branch
					

Using Git: Diff & Difftool


					git diff #Diff w/ Index / Working Directory
					

					git diff HEAD #Diff w/ HEAD / Working Directory
					

					git diff <sha1> <sha2> #Diff w/ two commits
					

					git difftool <...> #Better diff and for images
					

Exercise: 04

Create a branch where you will add your hobby to the bio, push it to GitHub.

Diff(tool) it with the master, merge and push to GitHub.

Using Git: Tags


					git tag #List existing tags
					

					git tag -a <tagname> -m 'messagetext' #Create a version tag, tagname = v1.0
					

					git push origin <tagname> # Push a tag to the remote repository
					

Exercise: 05

Create v0.1 and push it to GitHub

Git: Fetch


					git fetch <name of the remote> #Fetch a remote repo
					

And then compare it (it is a local "remote" branch for example origin/master) (see http://stackoverflow.com/a/1331459


					git diff --stat <name of the branch> <name of the fetched branch>
					

For example:


					git diff --stat master origin/master
					

Do your diff/modifications and then merge (while in your master or where you want to merge)


					git merge <name of the fetched branch>
					

For example:


					git merge origin/master
					

Git: Checkout/Reset


					git checkout <name of the branch> #Switch to another branch
					

					git checkout master #Go back to master branch
					

					git reset --hard <sha> #Replace working dir with a specific commit
					

					git checkout <sha> <filename> #Get a file from a specific commit
					

					git checkout <sha> #Go back in time at a specific commit
					

But then follow the next slide...

Git: Checkout & Detached Head


					git checkout <sha> #Go back in time at a specific commit
					

You will get a Detached Head, so... you can go back to master and nothing happens (if you just wanted to check things in history)


					git checkout master  #Go back to master and fix the detached head
					

...or you do your work/modifications in this way:


					git branch <name of the branch> #But then create e new branch from this point in time
					

					git checkout <name of the branch> #Go to the new branch!
					

					... #Do your modifications
					

					git checkout master  #Go to master
					

					git merge <name of the branch> #Update master with the branch you created
					

					git branch -d <name of the branch> #Delete that branch if not needed
					

Source: http://stackoverflow.com/questions/5772192/git-how-can-i-reconcile-detached-head-with-master-origin

Exercise: 06

Get from history your first version of the bio, and push it to GitHub.

Using Git: Merge files

Whenever merge fails...you need to merge manually


  					CONFLICT (content): Merge conflict in index.html
  					Automatic merge failed; fix conflicts and then commit the result.
					

For text files: manually or


					git mergetool
					

For binary/other files: manually or


					git checkout --theirs <filename> #Keep their/remote file
					

					git checkout --ours <filename> #Keep my/local file
					

And then add + commit!


					git add <filename> #Add the solved/merged file(s)
					

					git commit -m "..."
					

Source: http://gitready.com/advanced/2009/02/25/keep-either-file-in-merge-conflicts.html

Thank you!

Massimo Menichinelli / info@openp2pdesign.org / @openp2pdesign

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License.

Massimo Menichinelli 2014-2015
openp2pdesign.org