Git a starter kit

Post on 07-May-2015

908 views 7 download

Transcript of Git a starter kit

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

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

Appetizer

Who knows git? Who uses git?

Main dish

Basic git commands

Dessert

Questions & Answers

What is What is

What is What is What is What is

Git

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

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

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

Simple Fast

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

Mac: $ brew install git

Linux: $ apt-get install git-core

Windows: msysgit

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

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

$ git config --global user.email \ "boubacar@kareea.com"

$ cat ~/.gitconfig

152Commands

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

--++ 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)

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

$ git clone <url>

$ git clone git@github.com:username/project.git

Create local depot

Fetch remote master branch with commit history

Save it as local master branch

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

$ cd path/to/repos

$ mkdir project

$ cd project

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

$ ls -al # dir is empty

$ git init # initialize git repo

$ ls -al # new .git dir

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

Holds current checkout of files you are working on

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

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

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

Start coding/adding files

$ echo "Please read me" > README

$ echo "Learn git now!" > TODO

--++ 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

--++ 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

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

Index now contains working dir content

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

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

--++ 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)

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

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

Update files

$ echo "Try to cook" > TODO

$ echo "Once upon a time" > README

--++ 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)

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

$ git log

Print log of commits of current branch

Gives hashes, authors, descriptions, dates

$ git log --pretty

--++ 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

--++ 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

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

$ cat README

$ git checkout bb788e7e5d2059...

$ cat README

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

--++ 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)

--++ 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

--++ 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

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

$ git checkout master # Switch to master

$ git stash list

$ git stash show

$ git stash (apply || drop)

--++ 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

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

$ git add new_file

$ git commit -m "Testing new functionnality"

$ git checkout master

$ cat new_file

$ git merge new_functionnality

--++ 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

--++ 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 git@github.com:username/hello_world.git

$ git push <remote_depot> <remote_branch>

$ git push origin master

Formation rapide en vidéo

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

Any Question?

@BoubacarDiallo @Tutorys

--++ 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

--++ 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/