Collaborative development with git

Post on 21-Jul-2015

84 views 2 download

Tags:

transcript

Introduction to collaborative

development with gitPatrick JL Laso

@jl_laso www.patricklaso.com

http://www.slideshare.net/jlaso

Rev.1.0

Are you a solo developer ?Even if you are alone, you can improve your productivity.

How not work alone

FTP

Why not ?

• You cannot control versions

• You cannot recover last operative version

• You have to upload all files to be sure that the production version works fine as local works

Or a team ?Some order is needed to go ahead

Ready to jump ?Collaborative development with git

Well, let's go then!

What is GIT ?

What is GIT ?GIT is a source control management (SCM) that

allows developers to have controlled all versions and premises about collaboration

between the team members.!Once you now how it works rarely you will

think in work in other way. The principle is that all the sources reside in a central repository and all members have a copy of it, in local.

Through commands the changes are uploaded/downloaded from/to central repository.

Let's see how works

But … this is all ?

But … this is all ?

NO

Roberta John Julia

Development team

master develop

Roberta John Julia

Development team

master develop

Roberta John Julia

Development team

production server

master

master develop

Roberta John Julia

Development team

master develop

Roberta John Julia

Development teamgit fetch origin develop:develop

master develop

Roberta John Julia

Development teamgit fetch origin develop:develop

master develop

Roberta John Julia

Development teamgit fetch origin develop:develop

master develop

master develop

Roberta John Julia

Development teamgit fetch origin develop:develop

master develop

some work in local

master develop

Roberta John Julia

Development teamgit fetch origin develop:develop

master develop

some work in local

master develop

Roberta John Julia

Development teamgit fetch origin develop:develop

master develop

some work in local

git push origin develop

Best practicesDon't use always master branch

• The develop branch is the base • We create a feature branch in order to

develop a new functionality • We can test this functionality locally or in

other pre-staging server • Once all it's OK we have to merge this

feature branch to develop branch, and the deploy in staging server to test the whole product

• Lastly we have to create a release to merge changes on master branch and finally deploy in production

Roadmap

• The develop branch is the base • We create a feature branch in order to

develop a new functionality • We can test this functionality locally or in

other pre-staging server • Once all it's OK we have to merge this

feature branch to develop branch, and the deploy in staging server to test the whole product

• Lastly we have to create a release to merge changes on master branch and finally deploy in production

Roadmapgit checkout -b feature/new-functionallity

• The develop branch is the base • We create a feature branch in order to

develop a new functionality • We can test this functionality locally or in

other pre-staging server • Once all it's OK we have to merge this

feature branch to develop branch, and the deploy in staging server to test the whole product

• Lastly we have to create a release to merge changes on master branch and finally deploy in production

Roadmapgit checkout -b feature/new-functionallity

git checkout develop !git merge —no-ff feature/new-functionallity

master

developfeature

release

git checkout -b new-branchgit merge —no-ff branch-to-mergegit push origin local-branch

git fetch origin feature:feature

sysadmin, jenkins, automatic deploy, etc

Some commandsFirst learn to use console

Some git commandsclone git clone url folder

branches list local branches: git branch remote branches: git branch -r

get branch git fetch origin remote-branch:local-branch

status git status

stashgit stash git stash list git stash pop git stash clear

processgit add -A git commit -e git pull origin git push origin branch

SamplesHow to use git in the real world

Create a repo in our server• our server has the IP 192.168.1.1

• our git user is gituser

• we have to create a ssh relation*

• git init --bare /var/git/sample.git

Clone in local the repo• git clone gituser@192.168.1.1:/var/git/sample.git /home/user/projects/sample

Create local repository• cd /home/user/projects/sample

• git init

Assign remote in existing local repository

• cd /home/user/projects/sample

• git remote add origin gituser@192.168.1.1/var/git/sample.git

Commit all changes in local

• git add -A

• git commit -m "message to commit"

Update local from remote• git pull origin

all the changes in local files have to be committed or stashed before to use pull.

Save changes in clipboard (stash)

• git stash

stash

See stash's contents• git stash list

stash

Recover last stash• git stash apply # apply changes w/o erasing from stash

• git stash pop # extracts and apply contents from stash

stash

Clear contents of stash• git stash clear

stash

Update remote from local• git push origin branch

before to use push we have to use pull in order to update our local repo with content of remote and resolve posible conflicts first.

Create branch from existing

• git checkout -b new-branch

Merge branch with current

• git merge --no-ff branch-to-merge

commercial gitservers that use git

github.com

• github.com allows to create repositories through its graphic interface

• we can get the url to clone from page just created

• then is as you have a private server

github.com

• github.com allows to create repositories through its graphic interface

• we can get the url to clone from page just created

• then is as you have a private server

Create projects in github.comWe can create public repositories for free

bitbucket.org

• bitbucket.org allows to create repositories through its graphic interface

• we can get the url to clone from page just created

• then is as you have a private server

bitbucket.org

• bitbucket.org allows to create repositories through its graphic interface

• we can get the url to clone from page just created

• then is as you have a private server

Create projects in bitbucket.orgWe can create private or public repositories

More infohttp://git-scm.com/documentation!

!https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf!

Thank youPatrick JL Laso

@jl_laso www.patricklaso.com

http://www.slideshare.net/jlaso