Git a starter kit

46
Git: a starter kit --++ --++ Boubacar Diallo, Kareea. --++ --++ --++ --++ --++ --++ --++ --++ --

Transcript of Git a starter kit

Page 1: Git a starter kit

Git: a starter kit --++ --++ Boubacar Diallo, Kareea. --++ --++ --++ --++ --++ --++ --++ --++ --

Page 2: Git a starter kit

--++ Menu --++ --++ --++ --++ --++ --++ --++ --++ --++ --++ --++ --++

Appetizer

Who knows git? Who uses git?

Main dish

Basic git commands

Dessert

Questions & Answers

Page 3: Git a starter kit

What is What is

What is What is What is What is

Git

Page 4: Git a starter kit

--++ Not CVS or SVN --++ --++ --++ --++ --++ --++ --++ --++ --++

Page 5: Git a starter kit

--++ Distributed RCS --++ --++ --++ --++ --++ --++ --++ --++ --++

Page 6: Git a starter kit

--++ What is git? --++ --++ --++ --++ --++ --++ --++ --++ --++ --++

Simple Fast

Page 7: Git a starter kit

--++ Getting git --++ --++ --++ --++ --++ --++ --++ --++ --++ --++ --++

Mac: $ brew install git

Linux: $ apt-get install git-core

Windows: msysgit

Page 8: Git a starter kit

--++ Setup --++ --++ --++ --++ --++ --++ --++ --++ --++ --++ --++ --++

$ git config --global user.name "Boubacar Diallo"

$ git config --global user.email \ "[email protected]"

$ cat ~/.gitconfig

Page 9: Git a starter kit

152Commands

W00T, LOL, OMG, HAXX W00T, LOL, OMG, HAXX

Page 10: Git a starter kit
Page 11: Git a starter kit

Page 12: Git a starter kit

Page 13: Git a starter kit
Page 14: Git a starter kit

--++ Basic Usage --++ --++ --++ --++ --++ --++ --++ --++ --++ --++

• Clone existing depot (git clone)

• Initialize git depot (git init)

• Add a file (git add)

• Commit changes (git commit)

• See logs (git log)

• Remove a file (git rm)

• Jump to a commit (git checkout)

Page 15: Git a starter kit

--++ Clone existing depot --++ --++ --++ --++ --++ --++ --++ --++

$ git clone <url>

$ git clone [email protected]:username/project.git

Create local depot

Fetch remote master branch with commit history

Save it as local master branch

Page 16: Git a starter kit

--++ Make a new project --++ --++ --++ --++ --++ --++ --++ --++

$ cd path/to/repos

$ mkdir project

$ cd project

Page 17: Git a starter kit

--++ Initialize git depot --++ --++ --++ --++ --++ --++ --++ --++ --++

$ ls -al # dir is empty

$ git init # initialize git repo

$ ls -al # new .git dir

Page 18: Git a starter kit

--++ Working directory --++ --++ --++ --++ --++ --++ --++ --++ --++

Holds current checkout of files you are working on

Page 19: Git a starter kit

--++ Index zone --++ --++ --++ --++ --++ --++ --++ --++ --++ --++ --++

Index is used as a staging area between your working dir and your repository

Page 20: Git a starter kit

--++ Add a file --++ --++ --++ --++ --++ --++ --++ --++ --++ --++ --++

Start coding/adding files

$ echo "Please read me" > README

$ echo "Learn git now!" > TODO

Page 21: Git a starter kit

--++ Add a file --++ --++ --++ --++ --++ --++ --++ --++ --++ --++ --++

Files are added into a buffer zone (index)

Content of this zone is included in the next commit

Now git will track the changes made to these files

Page 22: Git a starter kit

--++ Show changes --++ --++ --++ --++ --++ --++ --++ --++ --++

Show the status of index and working dir

$ git status # files are untracked

$ git add README # add content to index

$ git add TODO # add content to index

$ git status # changes ready to be commited

Page 23: Git a starter kit

--++ Show changes --++ --++ --++ --++ --++ --++ --++ --++ --++

Index now contains working dir content

Page 24: Git a starter kit

--++ Commit changes --++ --++ --++ --++ --++ --++ --++ --++ --++

A commit is a snapshot taken from the index at some point in time

Page 25: Git a starter kit

--++ Commit changes --++ --++ --++ --++ --++ --++ --++ --++ --++

Saves the contents of index to the repo

Commit is inserted in the history of the branch

Each commit has an ID (SHA1 hash)

Page 26: Git a starter kit

--++ Commit changes --++ --++ --++ --++ --++ --++ --++ --++ --++

$ git commit -m “First commit” # First commit

Update files

$ echo "Try to cook" > TODO

$ echo "Once upon a time" > README

Page 27: Git a starter kit

--++ Commit changes --++ --++ --++ --++ --++ --++ --++ --++ --++

$ git status # Changes not staged for commit TODO + README

$ git add TODO # Changes to be commited TODO

$ git status # Changes not staged for commit

$ git commit -m "Update TODO file"

$ git status # Changes not staged for commit (README)

Page 28: Git a starter kit

--++ Print log commit --++ --++ --++ --++ --++ --++ --++ --++ --++

$ git log

Print log of commits of current branch

Gives hashes, authors, descriptions, dates

$ git log --pretty

Page 29: Git a starter kit

--++ Remove a file --++ --++ --++ --++ --++ --++ --++ --++ --++ --++

$ git rm <file>

Delete a file from the current directory

The file is no longer tracked by git

Next commit will contain instructions to remove the file

$ git rm TODO

Page 30: Git a starter kit

--++ Jump to a commit --++ --++ --++ --++ --++ --++ --++ --++ --

$ git checkout <commit ID>

Allows you to change the status of working directory

Files can be reverted to a previous version

Page 31: Git a starter kit

--++ Jump to a commit --++ --++ --++ --++ --++ --++ --++ --++ --

$ cat README

$ git checkout bb788e7e5d2059...

$ cat README

Page 32: Git a starter kit

--++ Add/commit workflow --++ --++ --++ --++ --++ --++ --++ --

Page 33: Git a starter kit
Page 34: Git a starter kit

--++ Intermediate Usage --++ --++ --++ --++ --++ --++ --++ --++ --

• Create branch (git branch branch_name)

• Put aside temporary changes (git stash)

• Merge branches (git merge)

• Push commits (git push)

• Pull commit (git pull)

Page 35: Git a starter kit

--++ Create a branch --++ --++ --++ --++ --++ --++ --++ --++ --++ --

$ git branch # List branches

$ git branch new_functionnality

Create branch that derives from current branch

Useful when developing a new feature

$ git checkout new_functionnality

$ git branch -D new_functionnality # Delete branch

Page 36: Git a starter kit

--++ Put aside changes --++ --++ --++ --++ --++ --++ --++ --++ --

Save temporary changes from index and working dir

$ git branch # branch new_functionnality

$ git status # Uncommited changes

$ git checkout master # Error

$ git stash # Saves working dir and index

Page 37: Git a starter kit

--++ Put aside changes --++ --++ --++ --++ --++ --++ --++ --++

$ git checkout master # Switch to master

$ git stash list

$ git stash show

$ git stash (apply || drop)

Page 38: Git a starter kit

--++ Merge branches --++ --++ --++ --++ --++ --++ --++ --++ --++ --

Merge a branch with the current branch

$ git checkout -b new_functionnality

$ echo "Take her phone" > TODO

$ echo "How to seduce women" > README

$ echo "Stop thinking too much" > new_file

Page 39: Git a starter kit

--++ Merge branches --++ --++ --++ --++ --++ --++ --++ --++ --++ --

$ git add new_file

$ git commit -m "Testing new functionnality"

$ git checkout master

$ cat new_file

$ git merge new_functionnality

Page 40: Git a starter kit

--++ Pull commits --++ --++ --++ --++ --++ --++ --++ --++ --++ --++ --

$ git pull <remote_depot> <remote_branch>

Download commit history of a remote branch (git fetch)

Performs merge with current branch (git merge)

Can generate conflicts

Page 41: Git a starter kit

--++ Push commits --++ --++ --++ --++ --++ --++ --++ --++ --++ --++

Sends commits to the history of a remote branch of a remote repository (help.github.com)

$ git remote add <name> <url>

$ git remote add origin [email protected]:username/hello_world.git

$ git push <remote_depot> <remote_branch>

$ git push origin master

Page 42: Git a starter kit
Page 43: Git a starter kit

Formation rapide en vidéo

--++ Thank you! --++ --++ --++ --++ --++ --++ --++ --++ --++ --++ --++

Any Question?

@BoubacarDiallo @Tutorys

Page 44: Git a starter kit

--++ Collaborative Working Process --++ --++ --++ --++ --++

Small commits with meaningful commit message

Test new functionnalities in separate branches

Merge branch into master

All tests should always pass on branch master

Push to staging when OK

Push to production

Page 46: Git a starter kit

--++ Videos --++ --++ --++ --++ --++ --++ --++ --++ --++ --++ --++ --++

Tom Preston-Werner - Mastering Git Basics http://vimeo.com/17118008

"Getting Git" by Scott Chacon http://vimeo.com/14629850

Linus Torvalds on Git http://www.youtube.com/watch?v=4XpnKHJAok8

Randal Schwartz on Git http://www.youtube.com/watch?v=8dhZ9BXQgc4

Git Tutorial Talk http://excess.org/article/2008/07/ogre-git-tutorial/