15. --++ 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
16. --++ Make a new project --++ --++ --++ --++ --++ --++ --++ --++
$ cd path/to/repos
$ mkdir project
$ cd project
17. --++ Initialize git depot --++ --++ --++ --++ --++ --++ --++ --++ --++
$ ls -al # dir is empty
$ git init # initialize git repo
$ ls -al # new .git dir
18. --++ Working directory --++ --++ --++ --++ --++ --++ --++ --++ --++
Holds current checkout of files you are working on
19. --++ Index zone --++ --++ --++ --++ --++ --++ --++ --++ --++ --++ --++
Index is used as a staging area between your
working dir and your repository
21. --++ 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
22. --++ 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
23. --++ Show changes --++ --++ --++ --++ --++ --++ --++ --++ --++
Index now contains working dir content
24. --++ Commit changes --++ --++ --++ --++ --++ --++ --++ --++ --++
A commit is a snapshot taken from the index at
some point in time
25. --++ 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)
26. --++ Commit changes --++ --++ --++ --++ --++ --++ --++ --++ --++
$ git commit -m “First commit” # First commit
Update files
$ echo "Try to cook" > TODO
$ echo "Once upon a time" > README
27. --++ 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)
29. --++ 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
30. --++ 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
35. --++ 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
36. --++ 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
37. --++ Put aside changes --++ --++ --++ --++ --++ --++ --++ --++
$ git checkout master # Switch to master
$ git stash list
$ git stash show
$ git stash (apply || drop)
38. --++ 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
40. --++ 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
41. --++ 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
42.
43. --++ Thank you! --++ --++ --++ --++ --++ --++ --++ --++ --++ --++ --++
Any Question?
Formation rapide en vidéo
@BoubacarDiallo @Tutorys
44. --++ 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