SlideShare a Scribd company logo
1 of 131
Download to read offline
Collaborative development with Git
Anuchit Chalothorn
anuchit@redlinesoft.net
Git Workshop
●
●
●
●
●
●
●

Overview
Git Basics
Undo Git Changes
Git Branches
Rewriting Git History
Git Remote Repository
Git Workflow
Overview
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. A VCS allows
you to:
●
●
●
●

revert files back to a previous state
revert the entire project back to a previous state
review changes made over time
see who last modified something
Local
Centralized
Distributed
History of Git
Linux Kernel was use DVCS call BitKeeper, proprietary
software but in 2005 the company behind BitKeeper brokedown and tool’s free-of-charge was revoked. The Linux
development community develop their own tool.
Goal of Git
● Speed
● Simple design
● Strong support for non-linear development (1000+ for
parallel branches)
● Fully distributed
● Able handle a large project (data and size)
Git Basic
Git basic tutorial provide the important commands to work
with Git
Get Git
Download git at http://git-scm.com/downloads choose your
os version :)
Workshop 1
Download Git and install to your machine, after install try to
use git command.
Git config
The git config command lets you configure your Git
installation (or an individual repository) from the command
line.
Git config user.name
Define the author name to be used for all commits in the
current repository. Typically, you’ll want to use the -global flag to set configuration options for the current
user.
git config --global user.name <name>
Git config user.email
Define the author email to be used for all commits by the
current user.
git config --global user.email <email>
Git config core.editor
Define the text editor used by commands like git commit for
all users on the current machine. eg; vi
git config --system core.editor <editor>
Git config core.autocrlf
Config the line ending for your operating system
git config --global core.autocrlf true
git config --global core.autocrlf input
Git config color.ui
Config the line color for git message
git config --global color.ui auto
Workshop 2
Setup Git config to your profile; name, email, line break, ui
auto color and choose your favorite text editor.
Git init
The git init command creates a new Git repository.
git init
git init <directory>
Git init --bare
Shared repositories should always be created with the -bare flag

Bare

Non
Bare

Non
Bare

Non
Bare
Example
cd /repo
git init --bare my-project.git

my-project.git
Workshop 3
Create git repositories call myrepo as working repository
and master-proj as shared repository, see what is
difference of two repository.
Git clone
The git clone command copies an existing Git repository.
git clone <repo>
git clone <repo> <directory>

Origin

Working Copy
Collaboration
Central Repo to Working Copy
Collaboration

Repo to Repo Collaboration

SVN
Repo

Git
Repo

Git
Repo

Git
Repo
Example
git clone ssh://username@example.com/repo/my-project.git
cd my-project

example.com/repo/my-project.git

local repo
Workshop 4
create local git repo call master-proj and clone
master-proj to myproj and create a blank file called
README
Git add
The git add command adds a change in the working
directory to the staging area.
git add <file>
git add <directory>
Example
git add .
git commit

Add

Commit

git add hello.php
git commit
Working
Directory

Staged
Snapshot

Committed
History
Workshop 5
Add README to your repository
Git commit
The git commit command commits the staged snapshot to
the project history.
git commit -m "<message>"
Example
git add hello.php
git commit

hello.php

hello.php

hello.php
Workshop 6
Commit all change to your repository, create snapshot to
project history.
Git status
The git status command displays the state of the working
directory and the staging area.
git status
Workshop 7
Use git status after add, edit file or commit file.
Git log
The git log command displays committed snapshots. It lets
you list the project history, filter it, and search for specific
changes.
Example
Git Status

git log

Git Log

git log -n <limit>
git log --oneline
git log --stat
git log --author="<pattern>"
git log --grep="<pattern>"
git log <since>..<until>

Working
Directory

Staged
Snapshot

Committed
History
Workshop 8
Use git log to see the committed history of your repository.
Undo Git Changes
Working with previous revisions of your software project.
Git checkout
The git checkout command serves three distinct functions:
checking out files, checking out commits, and checking out
branches.
git checkout master
git checkout <commit> <file>
git checkout <commit>
Example
git log --oneline
git checkout a1e8fb5

a1e8fb5

Master
Example
git checkout master
git checkout a1e8fb5 hello.py

Add

Working
Directory

Commit

Staged
Snapshot

Committed
History
Workshop 9
Add 2 lines in in readme.txt and commit change to your
repository, check revision form git log and try to change to
the first state and try to change state back to the latest
revision (master)
Git revert
The git revert command undoes a committed snapshot. it
the ‘safe’ way to undo.
git revert <commit>
Example
git commit -am “update readme”
git revert 15df9b6

15df9b6
Workshop 10
Add 1 lines in in readme.txt and commit change to your
repository, check revision form git log and try to revert to
previous version by using git revert
Git reset
The git reset command undo changes in dangerous
method — it is a permanent undo.
git reset <file>
git reset <commit>
git reset --hard
git reset --hard <commit>
Example
git commit -am “update readme”
git reset --hard 15df9b6
Workshop 11
Add 1 lines in in readme.txt and commit change to your
repository, check revision form git log and try to revert to
previous version by using git reset
Git clean
The git clean command removes untracked files from your
working directory.
git clean
git clean -f
git clean -df
git clean -xf
Example
touch somefile.txt
git reset --hard
git clean -df
Workshop 12
Create new file call index.php and try to use git clean
to delete untracked file.
Git Branches
First, we'll take a look at creating branches, which is like
requesting a new project history.
Git branch
The git branch command lets you create, list, rename, and
delete branches.
git branch
git branch <branch>
Example
git branch experiment
Master

Experiment
Workshop 12
Create new branch call issue123 for your current revision.
use git branch to show branches.
Git checkout
The git checkout command lets you navigate between the
branches created by git branch.
git checkout <existing-branch>
git checkout -b <new-branch>
Example
git branch experiment
git checkout experiment

Experiment

Master
Workshop 13
Change to branch issue123 add some file and commit to
this branch then change to master to compare.
Git merge
The git merge command lets you take the independent
lines of development created by git branch and
integrate them into a single branch.
Example
git merge experiment
git branch -d experiment
Experiment

Experiment

Master

Master
Workshop 14
Change to branch issue123 edit some file and commit
then change to master branch and merge issue123 to
master branch then delete issue123 branch.
Rewriting Git History
Git also designed to give you total control over your
development workflow, letting you define exactly what your
project history looks like; however, it also creates the
potential to lose commits.
Git rebase
Rebasing is the process of moving a branch to a new base
commit.
git rebase <base>
Example
feature
feature
feature

master
master
Example
# Start a new feature
git checkout -b feature master
# Edit files
git commit -a -m "Start developing a feature"
git checkout master
# Edit files
git commit -a -m "Fix security hole"
Example
# Merge back into master
git checkout feature
git rebase master
# Merge back into master
git checkout master
git merge feature
Git rebase -i
Running git rebase with the -i flag begins an interactive
rebasing session.
git rebase -i <base>
Example
# Start a new feature
git checkout -b feature master
# Edit files
git commit -a -m "Start developing a feature"
git checkout master
# Edit files
git commit -a -m "Fix security hole"
Example
# Merge back into master
git checkout feature
git rebase -i master
# Config merge method in change log
# Merge back into master
git checkout master
git merge feature
Workshop 15
● Initial git repo
○ add blank readme.txt and index.php
● Branch new feature from master call feature then
○ update index.php with some function
● Change branch to master
○ update readme.txt
● Change branch to feature
○ merge changes from base
● Change branch to master
○ merge feature to master
Git reflog
Git keeps track of updates to the tip of branches using a
mechanism called reflog.
git reflog
git reflog --relative-date
Example
git reflog
12aeb71 HEAD@{0}: merge feature: Fast-forward
df6c71f HEAD@{1}: reset: moving to df6c71f
12aeb71 HEAD@{2}: merge feature: Fast-forward
df6c71f HEAD@{3}: checkout: moving from feature to master
Example
git reflog --relative-date
12aeb71 HEAD@{9 minutes ago}: merge feature: Fast-forward
df6c71f HEAD@{11 minutes ago}: reset: moving to df6c71f
12aeb71 HEAD@{13 minutes ago}: merge feature: Fast-forward
df6c71f HEAD@{14 minutes ago}: checkout: moving from
feature to master
Workshop 16
Use git reflog to see changes and reset to any commit
revision.
Remote Repositories
Git’s collaboration model, which gives every developer their
own copy of the repository, complete with its own local
history and branch structure. Instead of committing a
changeset from a working copy to the central repository, Git
lets you share entire branches between repositories.
Quick Git Server (1)
# install ssh server and git
sudo apt-get install openssh-server
sudo apt-get install git
# add git user for all users access
sudo adduser --group sudo git
# then import user’s public key to .ssh/authorized_keys
sudo su git
cd
mkdir .ssh
cat id_rsa.john.pub >> .ssh/authorized_keys
Quick Git Server (2)
# Make git repo dir at /git for easy access
sudo mkdir /git
sudo chown git:git /git
# Make share repo called project.git
sudo su git
cd /git
git init --bare project.git
# Disable git user to ssh to server
sudo usermod -s /usr/bin/git-shell git
Workshop 17
● Setup git server add following users (or your team)
○ John
○ Jessie
○ Jessica
● Create share project called webapps
Git remote
The git remote command lets you create, view, and delete
connections to other repositories.
git remote
git remote add <name> <url>

origin

Central
Repo

git remote rm <name>

John’s
Repo

Jess’s
Repo
Example
# on John’s computer
cd myproject
git init
git add .
git commit -m 'initial commit'
git remote add origin git@gitserver:/git/project.git
git push origin master
Example
# on John’s computer
git clone git@gitserver:/git/project.git myproject
cd myproject
touch README
git add README
git commit -am “add readme”
git push origin master
Workshop 18
● Lets John first commit following files to repository
○ README
○ LICENSE
○ CONTRIBUTOR
● Another users clone repository to their machine
Git fetch
The git fetch command imports commits from a remote
repository into your local repo.
git fetch <remote>
git fetch <remote> <branch>
Example
cd myproject
git init
git remote add origin git@gitserver:/git/project.git
git fetch origin
git checkout master
git merge origin/master
Workshop 19
● Lets Jessica create feature branch and commit to
repository
● Another users fetch feature branch from repository to
their machine
Git pull
The git pull command merge upstream changes into your
local repository, it’s combined git fetch and git merge in
single command.
git pull <remote>
git pull --rebase <remote>
Example
cd myproject
git init
git remote add origin git@gitserver:/git/project.git
git checkout master
git pull --rebase origin
Workshop 20
Create working repository in machine and add remote
repository and use git pull to merge remote repository to
working repository.
Git push
The git pull command merge upstream changes into your
local repository, it’s combined git fetch and git merge in
single command.
git push
git push <remote>
Example
echo “this is a readme” > README
git commit -am “update readme”
git push origin master

origin

John’s
Repo

Central
Repo

Jess’s
Repo
Workshop 21
Create working repository in machine and add remote
repository and use git pull to merge remote repository to
working repository. Edit some file and push to remote
repository
Git Workflows
The possible workflows can make it hard to know where to
begin when implementing Git in the workplace. These
workflows are designed to be guidelines rather than
concrete rules.
Centralized Workflow
The Centralized Workflow uses a
central repository to serve as the
single point-of-entry for all changes to
the project. Instead of trunk, the
default development branch is called
master and all changes are committed
into this branch.
Example
# Initialized central repository on server
git init --bare /part/to/repo.git
Example
# developer clone from repository
git clone ssh://user@host/path/to/repo.git
Example
# John done his feature
git status
git add
git commit
git push origin master
Example
# Jessie try to push her feature
git push origin master
# Git will refuse the request with a rather
verbose error message. She needs to pull
John’s updates into her repository, integrate
them with her local changes, and then try
again.
Example
# Jessie rebase on top of John’s commit
git pull --rebase origin master
Example
# Jessie and John working on relate feature
rebasing process will generate conflicts
git status
git add <somefile>
git rebase --continue
# If you get to this point and you have no idea what’
s going on, don’t panic. Just execute following
command and you’ll be right back.
git rebase --abort
Example
# Jessie successfully push her feature
git push origin master
Workshop 22
●
●
●
●

Group 2-3 people
Setup your team git repository server.
Use centralized workflow to fix code in sample application.
Sample application can pull from https://github.
com/anoochit/git-workshop.git
Feature Branch Workflow
the Centralized Workflow, adding feature branches to your
development process is an easy way to encourage
collaboration and streamline communication between
developers.
Feature

Master

Issue #123
Example
# clone from repository
git clone ssh://user@host/path/to/repo.git
Example
# Jessie branch new feature
git checkout -b jessie-feature master

git status
git add <some-file>
git commit
Example
# Jessie push her feature
git push -u origin jessie-feature
Example
# Jessie push her feature to remote repository
git push
Example
# John is ready to accept the pull request,
someone needs to merge the feature into the
stable project (this can be done by either John
or Jessie):
git checkout master
git pull
git pull origin jessie-feature
git push
Workshop 23
●
●
●
●

Group 2-3 people
Setup your team git repository server.
Use feature branch workflow to fix code in sample application.
Sample application can pull from https://github.
com/anoochit/git-workshop.git
Git Flow Workflow
The Gitflow Workflow defines a strict branching model
designed around the project release. While somewhat more
complicated than the Feature Branch Workflow, this
provides a robust framework for managing larger projects.
v0.1

Master

Developer

Feature

v0.2

v0.3

v0.4
v0.1

Master

Developer

Feature

Release

v0.2

v0.3

v1.0
Example
# Jessie create development branch from master
git checkout -b develop master
git push -u origin developer
Example
# John add new feature
git checkout -b feature developer
git status
git add <file>
git commit
Example
# John ready to merge feature to development
git pull origin developer
git checkout developer
git merge feature
git push
git branch -d feature
Example
# Jessie prepare release
git checkout -b release-1.0 develop
git checkout master
git merge release-1.0
git tag -a 0.1 -m "Initial public release" master
git push --tags
git branch -d release-1.0
Example
# Discover some bugs
git checkout -b issue-123 master
# Fix some bugs
git checkout master
git merge issue-123
git push
git branch -d issue-123
Workshop 24
●
●
●
●

Group 2-3 people
Setup your team git repository server.
Use git flow workflow to fix code in sample application.
Sample application can pull from https://github.
com/anoochit/git-workshop.git
Forking Workflow
The Forking Workflow is fundamentally different than the other
workflows Instead of using a single server-side repository to act as the
“central” codebase, it gives every developer a server-side repository.
Each contributor has not one, but two Git repositories: a private local
and a public server-side.
Example
Project maintainer initialized official repository
git init --bare /part/to/repo.git

Official
Example
Another developers clone (fork) official repository.
git clone user@gitserver/user/repo.git

John

Official

Jessie
Example
Developer clone their own repository
git remote add upstream user@gitserver/user/repo.git
Example
Developer work their features
git checkout -b feature
# Edit some code
git commit -am “add feature”
Example
Developer publish their features
git push origin feature
Example
Project maintainer integrate their feature
1. Inspect the code
2. Pull code in local repository and
manually merge
git fetch user@gitserver/user/repo.git feature
# Inspect code
git checkout master
git merge FETCH_HEAD
Example
Developers synchronized with official
repository, the main codebase has moved
forward, other developers should
synchronize with the official repository
git pull upstream master
Workshop 25
●
●
●
●

Group 2-3 people
Setup your own git repository servers.
Use forking workflow to fix code in sample application.
Sample application can pull from https://github.
com/anoochit/git-workshop.git
Workshop 26
Discussion in your developer team, choose workflow or mix and match
your developer team. Present your idea, workflow to another groups
Future study
●
●
●
●
●

Git GUI Client
Git & GitHub Foundations Training
Git Documentation
Git Tutorial
Pro Git Book
Collaborative development with Git | Workshop

More Related Content

What's hot

The everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitThe everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitE Carter
 
Introduction to git and github
Introduction to git and githubIntroduction to git and github
Introduction to git and githubAderemi Dadepo
 
Git tutorial
Git tutorialGit tutorial
Git tutorialmobaires
 
Version Control & Git
Version Control & GitVersion Control & Git
Version Control & GitJason Byrne
 
Introduction to Git / Github
Introduction to Git / GithubIntroduction to Git / Github
Introduction to Git / GithubPaige Bailey
 
Version Control System - Git
Version Control System - GitVersion Control System - Git
Version Control System - GitCarlo Bernaschina
 
Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial IJim Yeh
 
GIT | Distributed Version Control System
GIT | Distributed Version Control SystemGIT | Distributed Version Control System
GIT | Distributed Version Control SystemMohammad Imam Hossain
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction TutorialThomas Rausch
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git TutorialSage Sharp
 
git-and-bitbucket
git-and-bitbucketgit-and-bitbucket
git-and-bitbucketazwildcat
 
A Practical Introduction to git
A Practical Introduction to gitA Practical Introduction to git
A Practical Introduction to gitEmanuele Olivetti
 

What's hot (20)

Intro to Git and GitHub
Intro to Git and GitHubIntro to Git and GitHub
Intro to Git and GitHub
 
The everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitThe everyday developer's guide to version control with Git
The everyday developer's guide to version control with Git
 
Git tutorial
Git tutorial Git tutorial
Git tutorial
 
Introduction to git and github
Introduction to git and githubIntroduction to git and github
Introduction to git and github
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git commands
Git commandsGit commands
Git commands
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git basic
Git basicGit basic
Git basic
 
Version Control & Git
Version Control & GitVersion Control & Git
Version Control & Git
 
Introduction to Git / Github
Introduction to Git / GithubIntroduction to Git / Github
Introduction to Git / Github
 
Version Control System - Git
Version Control System - GitVersion Control System - Git
Version Control System - Git
 
Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial I
 
GIT | Distributed Version Control System
GIT | Distributed Version Control SystemGIT | Distributed Version Control System
GIT | Distributed Version Control System
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction Tutorial
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
 
git-and-bitbucket
git-and-bitbucketgit-and-bitbucket
git-and-bitbucket
 
Git Tutorial
Git TutorialGit Tutorial
Git Tutorial
 
A Practical Introduction to git
A Practical Introduction to gitA Practical Introduction to git
A Practical Introduction to git
 
Git learning
Git learningGit learning
Git learning
 
Git basics
Git basicsGit basics
Git basics
 

Viewers also liked

DEVELOPMENT OF GIT AND CONGENITAL ANOMALIES OF GIT
DEVELOPMENT OF GIT AND CONGENITAL ANOMALIES OF GITDEVELOPMENT OF GIT AND CONGENITAL ANOMALIES OF GIT
DEVELOPMENT OF GIT AND CONGENITAL ANOMALIES OF GITapoorvaerukulla
 
component based softwrae engineering Cbse
component based softwrae engineering Cbsecomponent based softwrae engineering Cbse
component based softwrae engineering CbseSravs Dals
 
Docker for PHP Developers - ZendCon 2016
Docker for PHP Developers - ZendCon 2016Docker for PHP Developers - ZendCon 2016
Docker for PHP Developers - ZendCon 2016Chris Tankersley
 
2013 Social Admissions Report
 2013 Social Admissions Report   2013 Social Admissions Report
2013 Social Admissions Report Uversity, Inc.
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshopthemystic_ca
 
Computer-free Website Development Demo - WordPressDC Jan 2015
 Computer-free Website Development Demo - WordPressDC Jan 2015 Computer-free Website Development Demo - WordPressDC Jan 2015
Computer-free Website Development Demo - WordPressDC Jan 2015Anthony D. Paul
 
NTR Lab - bespoke software development in Russia
NTR Lab - bespoke software development in RussiaNTR Lab - bespoke software development in Russia
NTR Lab - bespoke software development in RussiaOlessya
 
Engine lab software hybrid cloud specialists
Engine lab software hybrid cloud specialistsEngine lab software hybrid cloud specialists
Engine lab software hybrid cloud specialistsJohn Rowan
 
Information Design Web Planning Mockup
Information Design Web Planning MockupInformation Design Web Planning Mockup
Information Design Web Planning MockupANGELA Smithers
 
Docker & PHP - Practical use case
Docker & PHP - Practical use caseDocker & PHP - Practical use case
Docker & PHP - Practical use caserjsmelo
 
Php development with Docker
Php development with DockerPhp development with Docker
Php development with DockerMichael Bui
 
Microservices without Servers
Microservices without ServersMicroservices without Servers
Microservices without ServersDev_Events
 
Docker for Developers - PNWPHP 2016 Workshop
Docker for Developers - PNWPHP 2016 WorkshopDocker for Developers - PNWPHP 2016 Workshop
Docker for Developers - PNWPHP 2016 WorkshopChris Tankersley
 
Git Workshop : Getting Started
Git Workshop : Getting StartedGit Workshop : Getting Started
Git Workshop : Getting StartedWildan Maulana
 

Viewers also liked (20)

Git training
Git trainingGit training
Git training
 
Git workshop
Git workshopGit workshop
Git workshop
 
DEVELOPMENT OF GIT AND CONGENITAL ANOMALIES OF GIT
DEVELOPMENT OF GIT AND CONGENITAL ANOMALIES OF GITDEVELOPMENT OF GIT AND CONGENITAL ANOMALIES OF GIT
DEVELOPMENT OF GIT AND CONGENITAL ANOMALIES OF GIT
 
Git workshop
Git workshopGit workshop
Git workshop
 
component based softwrae engineering Cbse
component based softwrae engineering Cbsecomponent based softwrae engineering Cbse
component based softwrae engineering Cbse
 
Docker for PHP Developers - ZendCon 2016
Docker for PHP Developers - ZendCon 2016Docker for PHP Developers - ZendCon 2016
Docker for PHP Developers - ZendCon 2016
 
2013 Social Admissions Report
 2013 Social Admissions Report   2013 Social Admissions Report
2013 Social Admissions Report
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshop
 
Computer-free Website Development Demo - WordPressDC Jan 2015
 Computer-free Website Development Demo - WordPressDC Jan 2015 Computer-free Website Development Demo - WordPressDC Jan 2015
Computer-free Website Development Demo - WordPressDC Jan 2015
 
NTR Lab - bespoke software development in Russia
NTR Lab - bespoke software development in RussiaNTR Lab - bespoke software development in Russia
NTR Lab - bespoke software development in Russia
 
Engine lab software hybrid cloud specialists
Engine lab software hybrid cloud specialistsEngine lab software hybrid cloud specialists
Engine lab software hybrid cloud specialists
 
Especialidade de inclusão 5
Especialidade de inclusão 5Especialidade de inclusão 5
Especialidade de inclusão 5
 
Information Design Web Planning Mockup
Information Design Web Planning MockupInformation Design Web Planning Mockup
Information Design Web Planning Mockup
 
MockupBuilder
MockupBuilderMockupBuilder
MockupBuilder
 
Docker & PHP - Practical use case
Docker & PHP - Practical use caseDocker & PHP - Practical use case
Docker & PHP - Practical use case
 
Php development with Docker
Php development with DockerPhp development with Docker
Php development with Docker
 
Microservices without Servers
Microservices without ServersMicroservices without Servers
Microservices without Servers
 
Docker for Developers - PNWPHP 2016 Workshop
Docker for Developers - PNWPHP 2016 WorkshopDocker for Developers - PNWPHP 2016 Workshop
Docker for Developers - PNWPHP 2016 Workshop
 
Git Workshop : Getting Started
Git Workshop : Getting StartedGit Workshop : Getting Started
Git Workshop : Getting Started
 
Spm file33
Spm file33Spm file33
Spm file33
 

Similar to Collaborative development with Git | Workshop

Git hub abduallah abu nada
Git hub   abduallah abu nadaGit hub   abduallah abu nada
Git hub abduallah abu nadaLama K Banna
 
Git cheat sheet
Git cheat sheetGit cheat sheet
Git cheat sheetLam Hoang
 
GITHappens, powerpoint about git and github
GITHappens, powerpoint about git and githubGITHappens, powerpoint about git and github
GITHappens, powerpoint about git and githubalidor4702
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?9 series
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubDSC GVP
 
Git Ninja KT (GitHub to GitLab)
Git Ninja KT (GitHub to GitLab)Git Ninja KT (GitHub to GitLab)
Git Ninja KT (GitHub to GitLab)Ashok Kumar
 
Git Developer Cheatsheet
Git Developer CheatsheetGit Developer Cheatsheet
Git Developer CheatsheetAbdul Basit
 
Git slides
Git slidesGit slides
Git slidesNanyak S
 
Git tutorial undoing changes
Git tutorial   undoing changesGit tutorial   undoing changes
Git tutorial undoing changesLearningTech
 
Advanced Web Development in PHP - Code Versioning and Branching with Git
Advanced Web Development in PHP - Code Versioning and Branching with GitAdvanced Web Development in PHP - Code Versioning and Branching with Git
Advanced Web Development in PHP - Code Versioning and Branching with GitRasan Samarasinghe
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践Terry Wang
 
Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践Terry Wang
 
Git from the trenches
Git from the trenchesGit from the trenches
Git from the trenchesNuno Caneco
 
Git for developers
Git for developersGit for developers
Git for developersHacen Dadda
 

Similar to Collaborative development with Git | Workshop (20)

Git hub abduallah abu nada
Git hub   abduallah abu nadaGit hub   abduallah abu nada
Git hub abduallah abu nada
 
Git cheat sheet
Git cheat sheetGit cheat sheet
Git cheat sheet
 
GITHappens, powerpoint about git and github
GITHappens, powerpoint about git and githubGITHappens, powerpoint about git and github
GITHappens, powerpoint about git and github
 
Git github
Git githubGit github
Git github
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHub
 
Git Ninja KT (GitHub to GitLab)
Git Ninja KT (GitHub to GitLab)Git Ninja KT (GitHub to GitLab)
Git Ninja KT (GitHub to GitLab)
 
Git Developer Cheatsheet
Git Developer CheatsheetGit Developer Cheatsheet
Git Developer Cheatsheet
 
Git Init (Introduction to Git)
Git Init (Introduction to Git)Git Init (Introduction to Git)
Git Init (Introduction to Git)
 
Git slides
Git slidesGit slides
Git slides
 
Git tutorial undoing changes
Git tutorial   undoing changesGit tutorial   undoing changes
Git tutorial undoing changes
 
Advanced Web Development in PHP - Code Versioning and Branching with Git
Advanced Web Development in PHP - Code Versioning and Branching with GitAdvanced Web Development in PHP - Code Versioning and Branching with Git
Advanced Web Development in PHP - Code Versioning and Branching with Git
 
Git
GitGit
Git
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践
 
Introduction into Git
Introduction into GitIntroduction into Git
Introduction into Git
 
Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践
 
Git from the trenches
Git from the trenchesGit from the trenches
Git from the trenches
 
Gn unify git
Gn unify gitGn unify git
Gn unify git
 
Git tips
Git tipsGit tips
Git tips
 
Git for developers
Git for developersGit for developers
Git for developers
 

More from Anuchit Chalothorn (20)

Flutter Workshop 2021 @ ARU
Flutter Workshop 2021 @ ARUFlutter Workshop 2021 @ ARU
Flutter Workshop 2021 @ ARU
 
Flutter workshop @ bang saen 2020
Flutter workshop @ bang saen 2020Flutter workshop @ bang saen 2020
Flutter workshop @ bang saen 2020
 
13 web service integration
13 web service integration13 web service integration
13 web service integration
 
09 material design
09 material design09 material design
09 material design
 
07 intent
07 intent07 intent
07 intent
 
05 binding and action
05 binding and action05 binding and action
05 binding and action
 
04 layout design and basic widget
04 layout design and basic widget04 layout design and basic widget
04 layout design and basic widget
 
03 activity life cycle
03 activity life cycle03 activity life cycle
03 activity life cycle
 
02 create your first app
02 create your first app02 create your first app
02 create your first app
 
01 introduction
01 introduction 01 introduction
01 introduction
 
Material Theme
Material ThemeMaterial Theme
Material Theme
 
00 Android Wear Setup Emulator
00 Android Wear Setup Emulator00 Android Wear Setup Emulator
00 Android Wear Setup Emulator
 
MongoDB Replication Cluster
MongoDB Replication ClusterMongoDB Replication Cluster
MongoDB Replication Cluster
 
MongoDB Shard Cluster
MongoDB Shard ClusterMongoDB Shard Cluster
MongoDB Shard Cluster
 
IT Automation with Chef
IT Automation with ChefIT Automation with Chef
IT Automation with Chef
 
IT Automation with Puppet Enterprise
IT Automation with Puppet EnterpriseIT Automation with Puppet Enterprise
IT Automation with Puppet Enterprise
 
Using PhoneGap Command Line
Using PhoneGap Command LineUsing PhoneGap Command Line
Using PhoneGap Command Line
 
OpenStack Cheat Sheet V2
OpenStack Cheat Sheet V2OpenStack Cheat Sheet V2
OpenStack Cheat Sheet V2
 
REST API with CakePHP
REST API with CakePHPREST API with CakePHP
REST API with CakePHP
 
Open Stack Cheat Sheet V1
Open Stack Cheat Sheet V1Open Stack Cheat Sheet V1
Open Stack Cheat Sheet V1
 

Recently uploaded

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

Collaborative development with Git | Workshop

  • 1. Collaborative development with Git Anuchit Chalothorn anuchit@redlinesoft.net
  • 2. Git Workshop ● ● ● ● ● ● ● Overview Git Basics Undo Git Changes Git Branches Rewriting Git History Git Remote Repository Git Workflow
  • 3. Overview 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. A VCS allows you to: ● ● ● ● revert files back to a previous state revert the entire project back to a previous state review changes made over time see who last modified something
  • 7. History of Git Linux Kernel was use DVCS call BitKeeper, proprietary software but in 2005 the company behind BitKeeper brokedown and tool’s free-of-charge was revoked. The Linux development community develop their own tool.
  • 8. Goal of Git ● Speed ● Simple design ● Strong support for non-linear development (1000+ for parallel branches) ● Fully distributed ● Able handle a large project (data and size)
  • 9. Git Basic Git basic tutorial provide the important commands to work with Git
  • 10. Get Git Download git at http://git-scm.com/downloads choose your os version :)
  • 11. Workshop 1 Download Git and install to your machine, after install try to use git command.
  • 12. Git config The git config command lets you configure your Git installation (or an individual repository) from the command line.
  • 13. Git config user.name Define the author name to be used for all commits in the current repository. Typically, you’ll want to use the -global flag to set configuration options for the current user. git config --global user.name <name>
  • 14. Git config user.email Define the author email to be used for all commits by the current user. git config --global user.email <email>
  • 15. Git config core.editor Define the text editor used by commands like git commit for all users on the current machine. eg; vi git config --system core.editor <editor>
  • 16. Git config core.autocrlf Config the line ending for your operating system git config --global core.autocrlf true git config --global core.autocrlf input
  • 17. Git config color.ui Config the line color for git message git config --global color.ui auto
  • 18. Workshop 2 Setup Git config to your profile; name, email, line break, ui auto color and choose your favorite text editor.
  • 19. Git init The git init command creates a new Git repository. git init git init <directory>
  • 20. Git init --bare Shared repositories should always be created with the -bare flag Bare Non Bare Non Bare Non Bare
  • 21. Example cd /repo git init --bare my-project.git my-project.git
  • 22. Workshop 3 Create git repositories call myrepo as working repository and master-proj as shared repository, see what is difference of two repository.
  • 23. Git clone The git clone command copies an existing Git repository. git clone <repo> git clone <repo> <directory> Origin Working Copy
  • 24. Collaboration Central Repo to Working Copy Collaboration Repo to Repo Collaboration SVN Repo Git Repo Git Repo Git Repo
  • 25. Example git clone ssh://username@example.com/repo/my-project.git cd my-project example.com/repo/my-project.git local repo
  • 26. Workshop 4 create local git repo call master-proj and clone master-proj to myproj and create a blank file called README
  • 27. Git add The git add command adds a change in the working directory to the staging area. git add <file> git add <directory>
  • 28. Example git add . git commit Add Commit git add hello.php git commit Working Directory Staged Snapshot Committed History
  • 29. Workshop 5 Add README to your repository
  • 30. Git commit The git commit command commits the staged snapshot to the project history. git commit -m "<message>"
  • 31. Example git add hello.php git commit hello.php hello.php hello.php
  • 32. Workshop 6 Commit all change to your repository, create snapshot to project history.
  • 33. Git status The git status command displays the state of the working directory and the staging area. git status
  • 34. Workshop 7 Use git status after add, edit file or commit file.
  • 35. Git log The git log command displays committed snapshots. It lets you list the project history, filter it, and search for specific changes.
  • 36. Example Git Status git log Git Log git log -n <limit> git log --oneline git log --stat git log --author="<pattern>" git log --grep="<pattern>" git log <since>..<until> Working Directory Staged Snapshot Committed History
  • 37. Workshop 8 Use git log to see the committed history of your repository.
  • 38. Undo Git Changes Working with previous revisions of your software project.
  • 39. Git checkout The git checkout command serves three distinct functions: checking out files, checking out commits, and checking out branches. git checkout master git checkout <commit> <file> git checkout <commit>
  • 40. Example git log --oneline git checkout a1e8fb5 a1e8fb5 Master
  • 41. Example git checkout master git checkout a1e8fb5 hello.py Add Working Directory Commit Staged Snapshot Committed History
  • 42. Workshop 9 Add 2 lines in in readme.txt and commit change to your repository, check revision form git log and try to change to the first state and try to change state back to the latest revision (master)
  • 43. Git revert The git revert command undoes a committed snapshot. it the ‘safe’ way to undo. git revert <commit>
  • 44. Example git commit -am “update readme” git revert 15df9b6 15df9b6
  • 45. Workshop 10 Add 1 lines in in readme.txt and commit change to your repository, check revision form git log and try to revert to previous version by using git revert
  • 46. Git reset The git reset command undo changes in dangerous method — it is a permanent undo. git reset <file> git reset <commit> git reset --hard git reset --hard <commit>
  • 47. Example git commit -am “update readme” git reset --hard 15df9b6
  • 48. Workshop 11 Add 1 lines in in readme.txt and commit change to your repository, check revision form git log and try to revert to previous version by using git reset
  • 49. Git clean The git clean command removes untracked files from your working directory. git clean git clean -f git clean -df git clean -xf
  • 50. Example touch somefile.txt git reset --hard git clean -df
  • 51. Workshop 12 Create new file call index.php and try to use git clean to delete untracked file.
  • 52. Git Branches First, we'll take a look at creating branches, which is like requesting a new project history.
  • 53. Git branch The git branch command lets you create, list, rename, and delete branches. git branch git branch <branch>
  • 55. Workshop 12 Create new branch call issue123 for your current revision. use git branch to show branches.
  • 56. Git checkout The git checkout command lets you navigate between the branches created by git branch. git checkout <existing-branch> git checkout -b <new-branch>
  • 57. Example git branch experiment git checkout experiment Experiment Master
  • 58. Workshop 13 Change to branch issue123 add some file and commit to this branch then change to master to compare.
  • 59. Git merge The git merge command lets you take the independent lines of development created by git branch and integrate them into a single branch.
  • 60. Example git merge experiment git branch -d experiment Experiment Experiment Master Master
  • 61. Workshop 14 Change to branch issue123 edit some file and commit then change to master branch and merge issue123 to master branch then delete issue123 branch.
  • 62. Rewriting Git History Git also designed to give you total control over your development workflow, letting you define exactly what your project history looks like; however, it also creates the potential to lose commits.
  • 63. Git rebase Rebasing is the process of moving a branch to a new base commit. git rebase <base>
  • 65. Example # Start a new feature git checkout -b feature master # Edit files git commit -a -m "Start developing a feature" git checkout master # Edit files git commit -a -m "Fix security hole"
  • 66. Example # Merge back into master git checkout feature git rebase master # Merge back into master git checkout master git merge feature
  • 67. Git rebase -i Running git rebase with the -i flag begins an interactive rebasing session. git rebase -i <base>
  • 68. Example # Start a new feature git checkout -b feature master # Edit files git commit -a -m "Start developing a feature" git checkout master # Edit files git commit -a -m "Fix security hole"
  • 69. Example # Merge back into master git checkout feature git rebase -i master # Config merge method in change log # Merge back into master git checkout master git merge feature
  • 70. Workshop 15 ● Initial git repo ○ add blank readme.txt and index.php ● Branch new feature from master call feature then ○ update index.php with some function ● Change branch to master ○ update readme.txt ● Change branch to feature ○ merge changes from base ● Change branch to master ○ merge feature to master
  • 71. Git reflog Git keeps track of updates to the tip of branches using a mechanism called reflog. git reflog git reflog --relative-date
  • 72. Example git reflog 12aeb71 HEAD@{0}: merge feature: Fast-forward df6c71f HEAD@{1}: reset: moving to df6c71f 12aeb71 HEAD@{2}: merge feature: Fast-forward df6c71f HEAD@{3}: checkout: moving from feature to master
  • 73. Example git reflog --relative-date 12aeb71 HEAD@{9 minutes ago}: merge feature: Fast-forward df6c71f HEAD@{11 minutes ago}: reset: moving to df6c71f 12aeb71 HEAD@{13 minutes ago}: merge feature: Fast-forward df6c71f HEAD@{14 minutes ago}: checkout: moving from feature to master
  • 74. Workshop 16 Use git reflog to see changes and reset to any commit revision.
  • 75. Remote Repositories Git’s collaboration model, which gives every developer their own copy of the repository, complete with its own local history and branch structure. Instead of committing a changeset from a working copy to the central repository, Git lets you share entire branches between repositories.
  • 76. Quick Git Server (1) # install ssh server and git sudo apt-get install openssh-server sudo apt-get install git # add git user for all users access sudo adduser --group sudo git # then import user’s public key to .ssh/authorized_keys sudo su git cd mkdir .ssh cat id_rsa.john.pub >> .ssh/authorized_keys
  • 77. Quick Git Server (2) # Make git repo dir at /git for easy access sudo mkdir /git sudo chown git:git /git # Make share repo called project.git sudo su git cd /git git init --bare project.git # Disable git user to ssh to server sudo usermod -s /usr/bin/git-shell git
  • 78. Workshop 17 ● Setup git server add following users (or your team) ○ John ○ Jessie ○ Jessica ● Create share project called webapps
  • 79. Git remote The git remote command lets you create, view, and delete connections to other repositories. git remote git remote add <name> <url> origin Central Repo git remote rm <name> John’s Repo Jess’s Repo
  • 80. Example # on John’s computer cd myproject git init git add . git commit -m 'initial commit' git remote add origin git@gitserver:/git/project.git git push origin master
  • 81. Example # on John’s computer git clone git@gitserver:/git/project.git myproject cd myproject touch README git add README git commit -am “add readme” git push origin master
  • 82. Workshop 18 ● Lets John first commit following files to repository ○ README ○ LICENSE ○ CONTRIBUTOR ● Another users clone repository to their machine
  • 83. Git fetch The git fetch command imports commits from a remote repository into your local repo. git fetch <remote> git fetch <remote> <branch>
  • 84. Example cd myproject git init git remote add origin git@gitserver:/git/project.git git fetch origin git checkout master git merge origin/master
  • 85. Workshop 19 ● Lets Jessica create feature branch and commit to repository ● Another users fetch feature branch from repository to their machine
  • 86. Git pull The git pull command merge upstream changes into your local repository, it’s combined git fetch and git merge in single command. git pull <remote> git pull --rebase <remote>
  • 87. Example cd myproject git init git remote add origin git@gitserver:/git/project.git git checkout master git pull --rebase origin
  • 88. Workshop 20 Create working repository in machine and add remote repository and use git pull to merge remote repository to working repository.
  • 89. Git push The git pull command merge upstream changes into your local repository, it’s combined git fetch and git merge in single command. git push git push <remote>
  • 90. Example echo “this is a readme” > README git commit -am “update readme” git push origin master origin John’s Repo Central Repo Jess’s Repo
  • 91. Workshop 21 Create working repository in machine and add remote repository and use git pull to merge remote repository to working repository. Edit some file and push to remote repository
  • 92. Git Workflows The possible workflows can make it hard to know where to begin when implementing Git in the workplace. These workflows are designed to be guidelines rather than concrete rules.
  • 93. Centralized Workflow The Centralized Workflow uses a central repository to serve as the single point-of-entry for all changes to the project. Instead of trunk, the default development branch is called master and all changes are committed into this branch.
  • 94. Example # Initialized central repository on server git init --bare /part/to/repo.git
  • 95. Example # developer clone from repository git clone ssh://user@host/path/to/repo.git
  • 96. Example # John done his feature git status git add git commit git push origin master
  • 97. Example # Jessie try to push her feature git push origin master # Git will refuse the request with a rather verbose error message. She needs to pull John’s updates into her repository, integrate them with her local changes, and then try again.
  • 98. Example # Jessie rebase on top of John’s commit git pull --rebase origin master
  • 99. Example # Jessie and John working on relate feature rebasing process will generate conflicts git status git add <somefile> git rebase --continue # If you get to this point and you have no idea what’ s going on, don’t panic. Just execute following command and you’ll be right back. git rebase --abort
  • 100. Example # Jessie successfully push her feature git push origin master
  • 101. Workshop 22 ● ● ● ● Group 2-3 people Setup your team git repository server. Use centralized workflow to fix code in sample application. Sample application can pull from https://github. com/anoochit/git-workshop.git
  • 102. Feature Branch Workflow the Centralized Workflow, adding feature branches to your development process is an easy way to encourage collaboration and streamline communication between developers.
  • 104. Example # clone from repository git clone ssh://user@host/path/to/repo.git
  • 105. Example # Jessie branch new feature git checkout -b jessie-feature master git status git add <some-file> git commit
  • 106. Example # Jessie push her feature git push -u origin jessie-feature
  • 107. Example # Jessie push her feature to remote repository git push
  • 108. Example # John is ready to accept the pull request, someone needs to merge the feature into the stable project (this can be done by either John or Jessie): git checkout master git pull git pull origin jessie-feature git push
  • 109. Workshop 23 ● ● ● ● Group 2-3 people Setup your team git repository server. Use feature branch workflow to fix code in sample application. Sample application can pull from https://github. com/anoochit/git-workshop.git
  • 110. Git Flow Workflow The Gitflow Workflow defines a strict branching model designed around the project release. While somewhat more complicated than the Feature Branch Workflow, this provides a robust framework for managing larger projects.
  • 113. Example # Jessie create development branch from master git checkout -b develop master git push -u origin developer
  • 114. Example # John add new feature git checkout -b feature developer git status git add <file> git commit
  • 115. Example # John ready to merge feature to development git pull origin developer git checkout developer git merge feature git push git branch -d feature
  • 116. Example # Jessie prepare release git checkout -b release-1.0 develop git checkout master git merge release-1.0 git tag -a 0.1 -m "Initial public release" master git push --tags git branch -d release-1.0
  • 117. Example # Discover some bugs git checkout -b issue-123 master # Fix some bugs git checkout master git merge issue-123 git push git branch -d issue-123
  • 118. Workshop 24 ● ● ● ● Group 2-3 people Setup your team git repository server. Use git flow workflow to fix code in sample application. Sample application can pull from https://github. com/anoochit/git-workshop.git
  • 119. Forking Workflow The Forking Workflow is fundamentally different than the other workflows Instead of using a single server-side repository to act as the “central” codebase, it gives every developer a server-side repository. Each contributor has not one, but two Git repositories: a private local and a public server-side.
  • 120.
  • 121. Example Project maintainer initialized official repository git init --bare /part/to/repo.git Official
  • 122. Example Another developers clone (fork) official repository. git clone user@gitserver/user/repo.git John Official Jessie
  • 123. Example Developer clone their own repository git remote add upstream user@gitserver/user/repo.git
  • 124. Example Developer work their features git checkout -b feature # Edit some code git commit -am “add feature”
  • 125. Example Developer publish their features git push origin feature
  • 126. Example Project maintainer integrate their feature 1. Inspect the code 2. Pull code in local repository and manually merge git fetch user@gitserver/user/repo.git feature # Inspect code git checkout master git merge FETCH_HEAD
  • 127. Example Developers synchronized with official repository, the main codebase has moved forward, other developers should synchronize with the official repository git pull upstream master
  • 128. Workshop 25 ● ● ● ● Group 2-3 people Setup your own git repository servers. Use forking workflow to fix code in sample application. Sample application can pull from https://github. com/anoochit/git-workshop.git
  • 129. Workshop 26 Discussion in your developer team, choose workflow or mix and match your developer team. Present your idea, workflow to another groups
  • 130. Future study ● ● ● ● ● Git GUI Client Git & GitHub Foundations Training Git Documentation Git Tutorial Pro Git Book