36
GIT FOR DEVELOPERS

Git for developers

Embed Size (px)

Citation preview

Page 1: Git for developers

GIT FOR DEVELOPERS

Page 2: Git for developers

Hacen Dadda

◉ Web Developer◉ Consultant ◉ CTO @

@[email protected]://about.me/hacen

Page 3: Git for developers

BEFORE VCS

Page 4: Git for developers

BEFORE VCS

TIME

Page 5: Git for developers

BEFORE VCS

?

Page 6: Git for developers

BEFORE VCS

Page 7: Git for developers

A VERSION CONTROL

Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later. Even though the examples in this book show software source code as the files under version control, in reality any type of file on a computer can be placed under version control.

Page 8: Git for developers

WHAT IS GIT ?

In 2005, the Linux development community (and in particular Linus Torvalds) develop their own tool based on some of the lessons they learned while using BitKeeper. Some of the goals of the new system were as follows:

◉ Speed◉ Simple design◉ Strong support for non-linear development ◉ Fully distributed◉ Able to handle large projects

Page 9: Git for developers

WHY GIT ? Distributed

Page 10: Git for developers

WHO USE GIT ?

Page 11: Git for developers

BIG project ?

The linux kernel 3.13 release

◉ + 15 million line of code

◉ 12 000 non-megre commits ( non accepted code )

◉ 446K lines of code added

◉ 1 339 contributors

Page 12: Git for developers

INSTALLING GIT

◉ Linux (Ubuntu)

sudo apt-get install git-all

Or

sudo dpkg -i git_***.deb

◉ Windows

https://git-scm.com/download/win

◉ Mac

https://git-scm.com/download/mac

Page 13: Git for developers

Git Configuration

git config --global user.name "John Doe"

git config --global user.email [email protected]

Page 14: Git for developers

create a new repository

create a new directory, open it and perform a

git initto create a new git repository.

Page 15: Git for developers

checkout a repository

create a working copy of a local repository by running the command

git clone /path/to/repositorywhen using a remote server, your command will be

git clone username@host:/path/to/repository

Page 16: Git for developers

workflow

your local repository consists of three "trees" maintained by git. the

first one is your Working Directory which holds the actual files.

the second one is the Index which acts as a staging area and finally

the HEAD which points to the last commit you've made.

Page 17: Git for developers

workflow

Page 18: Git for developers

add & commit

You can propose changes (add it to the Index) using

git add <filename>

git add .This is the first step in the basic git workflow. To actually commit these changes use

git commit -m "Commit message"Now the file is committed to the HEAD, but not in your remote repository yet.

Page 19: Git for developers

log

in its simplest form, you can study repository history using.. git logYou can add a lot of parameters to make the log look like what you want.

To see a very compressed log where each commit is one line:

git log --pretty=onelineOr maybe you want to see an ASCII art tree of all the branches, decorated with the names of tags and branches:

git log --graph --oneline --decorate --all

Page 20: Git for developers

GITIGNORE

Page 21: Git for developers

Tools

Page 22: Git for developers

pushing changes

Your changes are now in the HEAD of your local working copy. To send those changes to your remote repository, execute

git push origin masterChange master to whatever branch you want to push your changes to.

If you have not cloned an existing repository and want to connect your repository to a remote server, you need to add it with

git remote add origin <server>Now you are able to push your changes to the selected remote server

Page 23: Git for developers

update & merge

to update your local repository to the newest commit, execute

git pull origin masterin your working directory to fetch and merge remote changes.

Page 24: Git for developers

branching

Branches are used to develop features isolated from each other. The master branch is the "default" branch when you create a repository. Use other branches for development and merge them back to the master branch upon completion.

Page 25: Git for developers

branching

create a new branch named "feature_x" and switch to it using

git checkout -b feature_xswitch back to master

git checkout masterand delete the branch again

git branch -d feature_x

Page 26: Git for developers

Create a new branch

git checkout -b some_feature

Page 27: Git for developers

branching

to merge another branch into your active branch (e.g. master), use

git merge <branch>in both cases git tries to auto-merge changes. Unfortunately, this is not always possible and results in conflicts. You are responsible to merge those conflicts manually by editing the files shown by git.

Page 28: Git for developers

Merge a branch

git checkout master

git merge some_feature

Page 29: Git for developers

Git workflow

Page 30: Git for developers

Basic branches

Page 31: Git for developers

Feature Branches

Page 32: Git for developers

Release Branches

Page 33: Git for developers

Maintenance Branches

Page 35: Git for developers

Workflow (Branching model)

Page 36: Git for developers

Any questions ?

Thanks!