SlideShare a Scribd company logo
Malihe Asemani
SDG-ITRC, Summer- 2012(1391)
asemani@itrc.ac.ir
ml.asemani@gmail.com
1
• Def:
– A system that records changes to a file or set of files(any type!) over time so
that you can recall specific versions later
• Used for:
– Revert files back to a previous state,
– Revert the entire project back to a previous state,
– Compare changes over time,
What is Version Control System?
– Compare changes over time,
– See who last modified something that might be causing a problem,
– Who introduced an issue and when,
– If you screw things up or lose files, you can easily recover.
– And more!
• Used by
– Graphic
– Web designer
– Developers
– And more!
2
Local Version Control System
• It creates local folders
• It is error prone
3
Centralized Version Control System
4
Centralized Version Control System
•It has a single server
•Clients check out the latest snapshot
5
Distributed Version Control System
6
Distributed Version Control System
• Git, Mercurial, Bazaar or Darcs
• Clients are fully repository mirror
7
Git History
• Linux kernel in 1992-2002:
– filing & archiving
• Linux kernel in 2002
– BitKeeper DVCS
8
Git History
• Linux kernel in 1992-2002:
– filing & archiving
• Linux kernel in 2002
– BitKeeper DVCS
• GIT a new DVCS• GIT a new DVCS
• Goals of New System by linus trovalds in 2005:
– Speed
– Simple design
– Strong support for non-linear development
(thousands of parallel branches)
– Fully distributed
9
How it works? (snapshots…)
• Snapshot, not differences (like CVS, Subversion, Perforce, Bazaar)
10
How it works?(Integrity…)
• Snapshot, not differences (like CVS, Subversion, Perforce, Bazaar)
• Nearly every operation is local
• Git has integrity
– Everything is check-summed before stored and referred to by that
– it’s impossible to change the contents of any file or directory without
Git knowing about it.Git knowing about it.
– SHA-1 hash:
• 40- hexadecimal character string
• calculated based on the contents of a file or directory structure in Git.
• 24b9da6552252987aa493b52f8696cd6d3b00373
11
How it works? (Undo…)
• Snapshot, not differences (like CVS, Subversion, Perforce, Bazaar)
• Nearly every operation is local
• Git has integrity
– Everything is check-summed before stored and referred to by that
– it’s impossible to change the contents of any file or directory without
Git knowing about it.Git knowing about it.
– SHA-1 hash:
• 40- hexadecimal character string
• calculated based on the contents of a file or directory structure in Git.
• 24b9da6552252987aa493b52f8696cd6d3b00373
• Git generally only adds data
– It is very difficult to get the system to do anything that is
not undoable
12
How it works? (states…)
• The three states
– Committed: Data is safely stored in your local database
– Modified: Files are changed but have not committed it to
database
– Staged: Marked a modified file in its current version to go– Staged: Marked a modified file in its current version to go
into next commit snapshot
Three States
• modified
• staged
• Commit
• modified
• staged
• Commit
Three main
sections
• Working directory
• Staged area
• Git directory
• Working directory
• Staged area
• Git directory
13
How it works? (main sections…)
• working directory:
– single checkout of one version of the project
– Files are pulled out of the compressed database in the Git directory and
placed on disk
• Staging:
– Simple file
– contained in Git directory– contained in Git directory
– stores information about what will go into your next commit
– sometimes referred to as the index
• Git directory
– stores the metadata and object database for your project
– most important part
– It is what is copied when you clone a repository from another
computer
14
How it works? (work flow…)
15
How it works? (work flow…)
• You modify files in your working directory.
• You stage the files, adding snapshots of them to
your staging area.
• You do a commit, which takes the files as they are
in the staging area and stores that snapshot
permanently to your Git directory.
16
Git basics
Git
add/
commit
Diff/log
Remote
GitInstall
Git
repo Branch
tag
17
Install
• apt-get install libcurl4-gnutls-dev
libexpat1-dev gettext libz-dev libssl-dev
• apt-get install git-core
Install
• /etc/gitconfig (--system)
• ~/.gitonfig (--global)Config
GitInstall
Git
repo
add/
commit
Diff/log
Remote
Branch
tag
• ~/.gitonfig (--global)
• Project-directory/.git/config
Config
$git config --global merge. Tool vimdiff
$git config --list
$git config user.name
$git config --global user.name “Asemani”
$git config --global user.mail
asemani@gmail.com
$git config --global core.editor vi
$git config --global merge. Tool vimdiff 18
Install
• apt-get install libcurl4-gnutls-dev
libexpat1-dev gettext libz-dev libssl-dev
• apt-get install git-core
Install
• /etc/gitconfig (--system)
Config
GitInstall
Git
repo
add/
commit
Diff/log
Remote
Branch
tag
• /etc/gitconfig (--system)
• ~/.gitonfig (--global)
• Project-directory/.git/config
Config
• git help <verb> : git help config
• git <verb> --help : git config --help
• man git-<verb> : man git-config
Help
19
Getting Git Repo
• Initializing a repository in an existing directory
(project)
– Go to the project directory
• $git init
GitInstall
Git
repo
add/
commit
Diff/log
Remote
Branch
tag
• $git init
– Add the files
• $ git add *.c
• $git add README
– Commit the files
• $git commit –m ‘initial project version’
20
Getting Git Repo…
• Initializing a Repository in an existing directory
(project)
• Cloning an existing repository :
– $git clone [url] Your_Dir
•$ git clone git://SERVER/USER/[REPO_PATH/]REPO.git
•$ git clone git://github.com/schacon/grit.git
git://
•$ git clone https://SERVER/USER/REPO.git
•$ git clone https://github.com/schacon/grit.git
https://
•$git clone ssh://USER@SERVER/REPO.git
•$git clone ssh://developer@dev.xamin.ir/native.gitssh://
21
ssh Example
• cd ~/.ssh
Check for SSH keys
• $ls
• $mkdir key_backup
Backup and remove existing SSH keys
• $mkdir key_backup
• cp id_rsa* key_backup
• rm id_rsa*
• ssh-keygen -t rsa -C "your_email@youremail.com"
• Enter path and pass phrase
Generate a new SSH key
• Done! Now, you can clone the repository on git server.
Send “id_rsa.pub ” to the SERVERS’s administrator
22
• File status life cycle
– Add
– Commit
– Remove
Add/Commit (status)
GitInstall
Git
repo
add/
commit
Diff/log
Remote
Branch
tag
– Remove
– Rename
23
• File status life cycle
Add/Commit (status)
commitUntracked unmodifide modifide Staged
Tracking files
GitInstall
Git
repo
add/
commit
Diff/log
Remote
Branch
tag
24
• File status life cycle
Add/Commit (status)
commitUntracked unmodifide modifide Staged
Tracking files
GitInstall
Git
repo
add/
commit
Diff/log
Remote
Branch
tag
Add the file
• You can remove the files from tracking/unmodified stage, too
25
• File status life cycle
Add/Commit (status)
commitUntracked unmodifide modifide Staged
Tracking files
GitInstall
Git
repo
add/
commit
Diff/log
Remote
Branch
tag
Edit the file
Add the file
26
• File status life cycle
Add/Commit (status)
commitUntracked unmodifide modifide Staged
Tracking files
GitInstall
Git
repo
add/
commit
Diff/log
Remote
Branch
tag
Edit the file
Add the file
Staged the file
27
• File status life cycle
Add/Commit (status)
commitUntracked unmodifide modifide Staged
Tracking files
GitInstall
Git
repo
add/
commit
Diff/log
Remote
Branch
tag
Commit file
Edit the file
Add the file
Staged the file
28
• File status life cycle
Add/Commit (status)
commitUntracked unmodifide modifide Staged
Tracking files
GitInstall
Git
repo
add/
commit
Diff/log
Remote
Branch
tag
Commit file
Edit the file
Add the file
Staged the file
Commit
29
• File status life cycle
– getting the file status:
• $git status
Add/Commit (status)
GitInstall
Git
repo
add/
commit
Diff/log
Remote
Branch
tag
– Notice to:
• Untracked files
• Nothing to commit (working directory clean)
• Changed but not updated
• Changes to be committed
30
• File status life cycle
– getting the file status:
• $git status
Add/Commit (status)
GitInstall
Git
repo
add/
commit
Diff/log
Remote
Branch
tag
– Notice to:
• Untracked files
• Nothing to commit (working directory clean)
• Changed but not updated
• Changes to be committed
31
Add/Commit (commands)
• Add files:
– $git add your_file_or_directory
– Multipurpose add: 1)begin tracking new files, 2)stage files, …
Track new file
• $vim README
$git status
• $ git add README
$ git status
• $vim benchmarks.rb
$ git status
• $ git add benchmarks.rb
$ git status
Staging modified files:
32
Add/Commit (commands)
• Commit:
– $git commit (It opens vi to add message)
– $git commit –m “your-message-goes-here”
– $git commit –a –m “your-message-goes-here” (Skip staged area)
• Remove
– $git rm <file_name> (Remove from git repo)
– $git rm --cached <your_file> (Remove from tracking files)
• Rename:
– $git mv <from_file> <to_file>
33
Add/Commit(Undo)
• Committing (Changing the last commit)
– $git commit -m 'initial commit'
– $git add <forgotten_file>
– $ git commit --amend
• Un-staging a staged file (Notice: status)• Un-staging a staged file (Notice: status)
– $git reset HEAD <filename>
• Un-modifying a modified file (Notice: status)
– $git checkout -- <filename>
• Deleted and overwritten commits are recoverable!
34
Dot(!) gitignore
• Ignoring:
– A class of files that you don’t want Git to
automatically add or even show you as being
untrackeduntracked
– .gitignore: listing all patterns that should be
ignored
• Ignoring files:
– $ cat .gitignore
• The rules
35
Dot(!) gitignore
• The rules
– The blank lines or lines starting with # are ignored.
– To specify a directory, end your patterns with “/”
– Negate a pattern by “!”
– “*” matches zero or more characters
– [abc] matches any character inside the brackets– [abc] matches any character inside the brackets
– “?” matches a single character
• Example:
– *~ (Ignore the temp files of Emacs)
– build/ # (Ignore all of the files in the build directory )
– doc/*.txt # (Ignore doc/notes.txt, but not doc/server/arch.txt)
– *.a # (Ignore the files which ends with .a)
– !lib.a # (but do track lib.a, even though you're ignoring .a files)
– /TODO # (Only ignore the root TODO file, not subdirectory /TODO)
36
diff
• We uses this command to:
– know what is changed, not just which files were changed (It is not same
as “git status” command)
– answer these two questions:
• What have you changed but not yet staged?
• What have you staged that you are about to commit?
– show the exact lines which are added and removed
GitInstall
Git
repo
add/
commit
Diff/log
Remote
Branch
tag
– show the exact lines which are added and removed
• To see what is modified but not it is not staged :
– $git diff (compares working directory with staging area)
• To see what is staged but is not committed:
– $git diff --cached
– $git diff --staged
37
log
• To Show commits on project reversely!
– $git log
• Each part of the ‘log’ command’s output contains: Sha1,
Author’s Name and Email, Date of commit, and the Commit Message
commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
Author: Scott Chacon <schacon@gee-mail.com>
Date: Sat Mar 15 16:40:33 2008 -0700
removed unnecessary test code
38
log…
• To Show commits on project reversely!
– $git log
• Each part of the ‘log’ command’s output contains: Sha1,
Author’s Name and Email, Date of commit, and the Commit Message
• Options:
– -p : Shows diff– -p : Shows diff
– -<#n>: shows n-th last commits
– --stat: shows statics for files modified in each commit: 1 files
changed, 1 insertions(+), 1 deletions(-)
– --pretty: The output format
• =Oneline
• =Short/full/fuller
• =format :"%h %s"
$ git log --since=2.weeks
$ git log --pretty="%h - %s" --author=gitster --since="2008-
10-01" --before="2008-11-01" --t/ 39
Log options description
• -p: Show the patch introduced with each commit.
• --stat: Show statistics for files modified in each commit.
• --shortstat: Display only the changed/insertions/deletions line from the --
stat command.
• --name-only: Show the list of files modified after the commit information.
• --name-status: Show the list of files affected with added/modified/deleted
information as well.information as well.
• --abbrev-commit: Show only the first few characters of the SHA-1
checksum instead of all 40.
• --relative-date: Display the date in a relative format (for example, “2
weeks ago”) instead of using the full date format.
• --graph: Display an ASCII graph of the branch and merge history
beside the log output.
• --pretty: Show commits in an alternate format. Options include oneline,
short, full, fuller, and format (where you specify your own format).
40
Log format options
• %H Commit hash
• %h Abbreviated commit hash
• %T Tree hash
• %t Abbreviated tree hash
• %P Parent hashes
• %p Abbreviated parent hashes
• %an Author name• %an Author name
• %ae Author e-mail
• %ad Author date (format respects the –date= option)
• %ar Author date, relative
• %cn Committer name
• %ce Committer email
• %cd Committer date
• %cr Committer date, relative
• %s Subject
41
RemotesGitInstall
Git
repo
add/
commit
Diff/log
Remote
Branch
tag
AddAdd
Remote repo
Working
directory
Staging area Local repo
PushPush
AddAdd
CommitCommit
FetchFetch
PullPull
42
Remotes …
• Showing your remotes
– $ git remote
– $ git remote –v (To show url)
GitInstall
Git
repo
add/
commit
Diff/log
Remote
Branch
tag
$ git clone git:// github.com/schacon/ticgit.git$ git clone git:// github.com/schacon/ticgit.git
$cd ticgit
$git remote
origin
$ git remote -v
origin git://github.com/schacon/ticgit.git
koke git://github.com/koke/grit.git
43
Remotes …
• Showing your remotes
– $ git remote
– $ git remote –v (To show url)
• Adding Remote Repositories(users repo)
– $git remote add [shortname] [url]
GitInstall
Git
repo
add/
commit
Diff/log
Remote
Branch
tag
– $git remote add [shortname] [url]
$ git remote add pb
git://github.com/paulboone/ticgit.git
$ git remote -v
origin git://github.com/schacon/ticgit.git
pb git://github.com/paulboone/ticgit.git
44
Remotes …
• Showing your remotes
– $ git remote
– $ git remote –v (To show url)
• Adding Remote Repositories(users repo)
– $git remote add [shortname] [url]
GitInstall
Git
repo
add/
commit
Diff/log
Remote
Branch
tag
– $git remote add [shortname] [url]
• Fetching from user repo
– $git fetch [remote-name] (no merge )
• Pulling from repo: (git clone automatically track
master branch)
– $git pull [remote-name] [branch-name] (Auto merge )
45
Remotes …
• Pushing to Your Remotes
– $ git push [remote-name] [branch-name]
• Inspecting a Remote
– $git remote show <remote-name>– $git remote show <remote-name>
• Removing and Renaming Remotes (Changes
your remote branch name, locally)
– $git remote rename <prev_name> <new_name>
– $git remote rm <branch_name>
46
Tag
• purposes
– tag specific points in history as being important
– mark release points
• Tags Types
– Lightweight
GitInstall
Git
repo
add/
commit
Diff/log
Remote
Branch
tag
– Lightweight
• it’s just a pointer to a specific commit
• Just like a branch that doesn’t change
– Annotated (recommended)
• stored as full objects in the Git database
• They’re checksummed
• contain the tagger name, e-mail, and date
• have a tagging message
• can be signed and verified with GNU Privacy Guard(GPG)
47
Tag…
• Verifying a Signed Tag
– need the signer’s public key in your keyring
– If don’t have the signer’s public key: “could not verify
the tag”
• Sharing Tags
– “git push” command doesn’t transfer tags
to remote servers
48
Tag…
• List your tags
– $ git tag
• Search a pattern in the tags
– $ git tag -l 'v1.4.2.*‘
• Lightweight tags:
– $git tag <Your_Tag>
– $git show <Your_Tag> (To show no more info)
• Annotated tags:
– git tag -a <Your_Tag> -m ‘<Tag_Message>’
– $git show <Your_Tag> (To show commit too)
49
Tag…
• Signed tags:
– $git tag -s <Your_Tag> -m ‘<Tag_Message>’
– $git show <Your_Tag> (To show GPG sign too)
• Verifying a signed tag
– $git tag -v <Your_Tag>– $git tag -v <Your_Tag>
• Tagging Later(Tag a specific commit)
– $git tag -a <Your_Tag> <commit_checksum> (or part of it!)
• Sharing Tags
– $git push <remote-name> <Your_Tag>
– $git push <remote-name> --tags (To push all tags)
50
Some tips & tricks
• Bach shell completion:
– Find file GitDir/contrib/completion/git-completion.bash
– For your user, copy it to home directory
– For all user, copy it to /etc/bash_completion.d/– For all user, copy it to /etc/bash_completion.d/
– add it to your .bashrc file
• Git Aliases
– $git config --global alias <your-Alias> <command>
– $git config --global alias.ci commit
51
Branch
You can have different versions of your source code!
GitInstall
Git
repo
add/
commit
Diff/log
Remote
Branch
tag
52
Branch…
• Every indexed file in stage area is a blob!
• Every commit has a tree of blobs
GitInstall
Git
repo
add/
commit
Diff/log
Remote
Branch
tag
53
Branch…
• Every indexed file in stage area is a blob!
• Every commit has a tree of blobs
GitInstall
Git
repo
add/
commit
Diff/log
Remote
Branch
tag
54
Branch…
• Every indexed file in stage area is a blob!
• Every commit has a tree of blobs
GitInstall
Git
repo
add/
commit
Diff/log
Remote
Branch
tag
55
What a Branch Is…
56
What a Branch Is…
$ git branch testing
57
What a Branch Is…
A special pointer called HEAD to
know what branch you’re currently on.
58
What a Branch Is…
$ git checkout testing
59
What a Branch Is…
$ git commit -m 'made a change'
60
What a Branch Is…
$ git checkout master
61
What a Branch Is…
$ git commit -m 'made other changes'
62
Basic Branch Commands
AddAdd
CommitCommit
Remote
repo
Working
directory
Staging
area
Local repo
PushPush
FetchFetch
Check outCheck out
PullPull
MergeMerge
63
Basic Branch Commands
• List the current branches: $git branch [-v]
• Create a new branch: $git branch <New_Branch>
• Change to a branch: $git checkout <Your_Branch>
• Create & change to a new branch: $git checkout –b <Your_Branch>
• Delete a branch: $git checkout –d <Your_Branch>
• Merge the branch into current branch: $git merge <Your_Branch>
• List current merged branches: $ git branch --merged
• List the non-merged branches: $ git branch --no-merged
• List all of local and remote branches: $git branch –a
• List all of remote tracking branches: $git branch –r
64
Branch merging
The branch story(!) case study:
1- Do work on a web site.
2- Create a branch for a new story you’re working on.
3- Do some work in that branch.
you’ll receive a call that another issue is critical and you need a
hotfix. You’ll do the following:
1- Create a branch to add the hotfix.
2- After it’s tested, merge the hotfix branch, and push
to production.
3- Switch back to your original story and continue
working.
65
Branch merging …
1- Do work on a web site.
66
Branch merging …
1- Do work on a web site.
2- Create a branch for a new story you are
working on:
$git checkout -b iss53
67
Branch merging …
1- Do work on a web site.
2- Create a branch for a new story you are
working on:
$git checkout -b iss53
3- Do some work in that branch:3- Do some work in that branch:
$vim index.html
$git commit -a -m 'added a new footer [issue 53] '
68
Branch merging …
1- Do work on a web site.
2- Create a branch for a new story you are
working on:
$git checkout -b iss53
3- Do some work in that branch:3- Do some work in that branch:
$vim index.html
$git commit -a -m 'added a new footer [issue 53] ‘
Another critical issue, and you need a hotfix!
69
Branch merging …
Another critical issue, and you need a hotfix!
1- Create a branch to add the hotfix:
$ git checkout master
$ git checkout -b 'hotfix'
$ vim index.html
$ git commit -a -m 'fixed the broken email address'
70
Branch merging …
Another critical issue, and you need a hotfix!
1- Create a branch to add the hotfix:
$ git checkout master
$ git checkout -b 'hotfix'
$ vim index.html
$ git commit -a -m 'fixed the broken email address‘
2- After it’s tested, merge the hotfix branch,
and push to production:
$git checkout master
$git merge hotfix
71
Branch merging …
Another critical issue, and you need a hotfix!
1- Create a branch to add the hotfix:
$ git checkout master
$ git checkout -b 'hotfix'
$ vim index.html
$ git commit -a -m 'fixed the broken email address‘
2- After it’s tested, merge the hotfix branch,
and push to production:
$git checkout master
$git merge hotfix
3- Switch back to your original story and
continue working:
$git branch -d hotfix
$ git checkout issue 53
$ vim index.html
$ git commit -a –m 'finished issue 53' 72
Branch merging …
• And now you want to merge issue 53:
$git checkout master
$git merge iss53
• What does the ‘merge’ command do?
1) It comes back to the common ancestor of branches1) It comes back to the common ancestor of branches
2) It creates a new snapshot from the last commit of branches
3) It creates a new commit point on master branch (C6)
4) It merges branches into the new commit point
73
• what if conflicts happen:
– $git merge iss53
Merge conflicts
$git merge iss53
#Auto-merging index.html
#CONFLICT (content): Merge conflict in index.html#CONFLICT (content): Merge conflict in index.html
#Automatic merge failed; fix conflicts and then commit the result
74
• what if conflicts happen:
– $git merge iss53
• Which files unmerged?
– $git status
Merge conflicts
[master*]$ git status[master*]$ git status
#index.html: needs merge
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in
working directory)
#
# unmerged: index.html
75
• what if conflicts happen:
– $git merge iss53
• Which files unmerged?
– $git status
• Vi files with confilict:
Merge conflicts
<<<<<<< HEAD:index.html
<div id="footer">contact : email.support@github.com</div>
=======
<div id="footer">
please contact us at support@github.com
</div>
>>>>>>> iss53:index.html
76
• what if conflicts happen:
– $git merge iss53
• Which files unmerged?
– $git status
• Vi files with confilict:
Merge conflicts
Headiss53
<<<<<<< HEAD:index.html
<div id="footer">contact : email.support@github.com</div>
=======
<div id="footer">
please contact us at support@github.com
</div>
>>>>>>> iss53:index.html
77
• what if conflicts happen:
– $git merge iss53
• Which files unmerged?
– $git status
• Vi files with confilict:
– Replace the conflict with one of the options, or merge them
Merge conflicts
– Replace the conflict with one of the options, or merge them
together:
<div id="footer">
please contact us at support@github.com
</div>
– And Then:
$git add
$git status
$git commit
78
Remote/Branch
79
Remote/Branch
80
Remote/Branch
81
Remote/Branch
82
Remote/Branch
83
Remote/Branch
• Push to a Branch on Remote
– $git push <remote-name> <local-branch> (push on tracking
branch)
– $git push <remote-name> <local-branch>:<remote-branch>
• Receive from Remote Branch• Receive from Remote Branch
– $git fetch <remote-name>
– $ git merge <remote-name>/<remote-branch>
• Delete a Remote Branches
– $git push <remote-name> :<remote-branch>
• Tracking a Branch on Remote:
– $ git checkout --track (remote-name)/(branch-name)
– $git checkout –b <local-branch> <remote-name>:<remote-branch>84
gitk!
•a graphical git Repository browser
–$cd YOUR_GIT_REPO_DIR
–$gitk
85
Ref
• The main reference: https://git-scm.com
Special Thanks to ITRC
86

More Related Content

PDF
Course 102: Lecture 10: Learning About the Shell
PDF
Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)
PPT
Introduction to Git
PDF
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
PDF
Git session-2012-2013
PDF
Redhat 6 & 7
PDF
Version control
PDF
Git in action
Course 102: Lecture 10: Learning About the Shell
Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)
Introduction to Git
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Git session-2012-2013
Redhat 6 & 7
Version control
Git in action

What's hot (19)

ODP
Introduction to Git
PPTX
Gitting out of trouble
PDF
Docking postgres
PDF
Data Publication and Discovery with Globus
PPTX
Backups
PPTX
Git hub ppt presentation
PDF
Software Packaging with RPM
DOCX
Linux basic commands
PDF
Docker Registry + Basic Auth
PDF
Configure, Pack and Distribute: An RPM Creation Workshop
PPT
RPM Packaging 101 (Old)
PPTX
Software management in linux
PDF
Introduction to Globus for System Administrators (GlobusWorld Tour - UMich)
PDF
CASPUR Staging System II
PDF
Postgre sql linuxcontainers by Jignesh Shah
PPTX
Git Presentation
PDF
Smau Milano 2016 - Fabio Alessandro Locati
PDF
Introduction to git
PDF
Mini git tutorial
Introduction to Git
Gitting out of trouble
Docking postgres
Data Publication and Discovery with Globus
Backups
Git hub ppt presentation
Software Packaging with RPM
Linux basic commands
Docker Registry + Basic Auth
Configure, Pack and Distribute: An RPM Creation Workshop
RPM Packaging 101 (Old)
Software management in linux
Introduction to Globus for System Administrators (GlobusWorld Tour - UMich)
CASPUR Staging System II
Postgre sql linuxcontainers by Jignesh Shah
Git Presentation
Smau Milano 2016 - Fabio Alessandro Locati
Introduction to git
Mini git tutorial
Ad

Viewers also liked (14)

PDF
PDF
SAFe-SA-Certificate
PPTX
Tucson Prairie Dawgs Final Presentation
PDF
1 subida serra da groba 1 oficial
PPTX
Human BIOERAGROUP
DOC
Adrian yANEZ
PDF
RAP Results7-6-16
PDF
QAI STC 2012 Plenary Keynote: Testing 3.0 - Pricing for Value
PPTX
Bermuda triangle
PDF
AriZona Beverage Company sucess case
DOCX
UNIT 5: FOOD AND BEVERAGE OPERATIONS MANAGEMENT
PDF
The Agile PMO PMI Pittsburgh Michael Nir
PDF
Open DataFest III - 3.14.16 - Day One Afternoon Sessions
SAFe-SA-Certificate
Tucson Prairie Dawgs Final Presentation
1 subida serra da groba 1 oficial
Human BIOERAGROUP
Adrian yANEZ
RAP Results7-6-16
QAI STC 2012 Plenary Keynote: Testing 3.0 - Pricing for Value
Bermuda triangle
AriZona Beverage Company sucess case
UNIT 5: FOOD AND BEVERAGE OPERATIONS MANAGEMENT
The Agile PMO PMI Pittsburgh Michael Nir
Open DataFest III - 3.14.16 - Day One Afternoon Sessions
Ad

Similar to Git basics (20)

PPTX
Git Basics for Software Version Management
PDF
Git basics for beginners
KEY
Let's Git this Party Started: An Introduction to Git and GitHub
PPTX
Git 101 for Beginners
PPTX
Version controll.pptx
PDF
Git hub
PPTX
Version Control with Git
PPTX
git.ppt.pptx power point presentation got Google internet
PPTX
Getting Started with Git: A Primer for SVN and TFS Users
PPTX
git github PPT_GDSCIIITK.pptx
PPTX
Git and github
PPTX
sample.pptx
PDF
Rc094 010d-git 2 - desconocido
PPTX
1-Intro to VC & GIT PDF.pptx
PPTX
Git and Github
PDF
Learning git
PPTX
Introduction to Git and Github
PPTX
Introduction to GitHub, Open Source and Tech Article
PPT
390a gitintro 12au
Git Basics for Software Version Management
Git basics for beginners
Let's Git this Party Started: An Introduction to Git and GitHub
Git 101 for Beginners
Version controll.pptx
Git hub
Version Control with Git
git.ppt.pptx power point presentation got Google internet
Getting Started with Git: A Primer for SVN and TFS Users
git github PPT_GDSCIIITK.pptx
Git and github
sample.pptx
Rc094 010d-git 2 - desconocido
1-Intro to VC & GIT PDF.pptx
Git and Github
Learning git
Introduction to Git and Github
Introduction to GitHub, Open Source and Tech Article
390a gitintro 12au

Recently uploaded (20)

PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
KodekX | Application Modernization Development
PDF
cuic standard and advanced reporting.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Cloud computing and distributed systems.
PDF
Empathic Computing: Creating Shared Understanding
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
KodekX | Application Modernization Development
cuic standard and advanced reporting.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Per capita expenditure prediction using model stacking based on satellite ima...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Machine learning based COVID-19 study performance prediction
Network Security Unit 5.pdf for BCA BBA.
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Electronic commerce courselecture one. Pdf
Unlocking AI with Model Context Protocol (MCP)
sap open course for s4hana steps from ECC to s4
Cloud computing and distributed systems.
Empathic Computing: Creating Shared Understanding
Building Integrated photovoltaic BIPV_UPV.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”

Git basics

  • 1. Malihe Asemani SDG-ITRC, Summer- 2012(1391) asemani@itrc.ac.ir ml.asemani@gmail.com 1
  • 2. • Def: – A system that records changes to a file or set of files(any type!) over time so that you can recall specific versions later • Used for: – Revert files back to a previous state, – Revert the entire project back to a previous state, – Compare changes over time, What is Version Control System? – Compare changes over time, – See who last modified something that might be causing a problem, – Who introduced an issue and when, – If you screw things up or lose files, you can easily recover. – And more! • Used by – Graphic – Web designer – Developers – And more! 2
  • 3. Local Version Control System • It creates local folders • It is error prone 3
  • 5. Centralized Version Control System •It has a single server •Clients check out the latest snapshot 5
  • 7. Distributed Version Control System • Git, Mercurial, Bazaar or Darcs • Clients are fully repository mirror 7
  • 8. Git History • Linux kernel in 1992-2002: – filing & archiving • Linux kernel in 2002 – BitKeeper DVCS 8
  • 9. Git History • Linux kernel in 1992-2002: – filing & archiving • Linux kernel in 2002 – BitKeeper DVCS • GIT a new DVCS• GIT a new DVCS • Goals of New System by linus trovalds in 2005: – Speed – Simple design – Strong support for non-linear development (thousands of parallel branches) – Fully distributed 9
  • 10. How it works? (snapshots…) • Snapshot, not differences (like CVS, Subversion, Perforce, Bazaar) 10
  • 11. How it works?(Integrity…) • Snapshot, not differences (like CVS, Subversion, Perforce, Bazaar) • Nearly every operation is local • Git has integrity – Everything is check-summed before stored and referred to by that – it’s impossible to change the contents of any file or directory without Git knowing about it.Git knowing about it. – SHA-1 hash: • 40- hexadecimal character string • calculated based on the contents of a file or directory structure in Git. • 24b9da6552252987aa493b52f8696cd6d3b00373 11
  • 12. How it works? (Undo…) • Snapshot, not differences (like CVS, Subversion, Perforce, Bazaar) • Nearly every operation is local • Git has integrity – Everything is check-summed before stored and referred to by that – it’s impossible to change the contents of any file or directory without Git knowing about it.Git knowing about it. – SHA-1 hash: • 40- hexadecimal character string • calculated based on the contents of a file or directory structure in Git. • 24b9da6552252987aa493b52f8696cd6d3b00373 • Git generally only adds data – It is very difficult to get the system to do anything that is not undoable 12
  • 13. How it works? (states…) • The three states – Committed: Data is safely stored in your local database – Modified: Files are changed but have not committed it to database – Staged: Marked a modified file in its current version to go– Staged: Marked a modified file in its current version to go into next commit snapshot Three States • modified • staged • Commit • modified • staged • Commit Three main sections • Working directory • Staged area • Git directory • Working directory • Staged area • Git directory 13
  • 14. How it works? (main sections…) • working directory: – single checkout of one version of the project – Files are pulled out of the compressed database in the Git directory and placed on disk • Staging: – Simple file – contained in Git directory– contained in Git directory – stores information about what will go into your next commit – sometimes referred to as the index • Git directory – stores the metadata and object database for your project – most important part – It is what is copied when you clone a repository from another computer 14
  • 15. How it works? (work flow…) 15
  • 16. How it works? (work flow…) • You modify files in your working directory. • You stage the files, adding snapshots of them to your staging area. • You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory. 16
  • 18. Install • apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev • apt-get install git-core Install • /etc/gitconfig (--system) • ~/.gitonfig (--global)Config GitInstall Git repo add/ commit Diff/log Remote Branch tag • ~/.gitonfig (--global) • Project-directory/.git/config Config $git config --global merge. Tool vimdiff $git config --list $git config user.name $git config --global user.name “Asemani” $git config --global user.mail asemani@gmail.com $git config --global core.editor vi $git config --global merge. Tool vimdiff 18
  • 19. Install • apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev • apt-get install git-core Install • /etc/gitconfig (--system) Config GitInstall Git repo add/ commit Diff/log Remote Branch tag • /etc/gitconfig (--system) • ~/.gitonfig (--global) • Project-directory/.git/config Config • git help <verb> : git help config • git <verb> --help : git config --help • man git-<verb> : man git-config Help 19
  • 20. Getting Git Repo • Initializing a repository in an existing directory (project) – Go to the project directory • $git init GitInstall Git repo add/ commit Diff/log Remote Branch tag • $git init – Add the files • $ git add *.c • $git add README – Commit the files • $git commit –m ‘initial project version’ 20
  • 21. Getting Git Repo… • Initializing a Repository in an existing directory (project) • Cloning an existing repository : – $git clone [url] Your_Dir •$ git clone git://SERVER/USER/[REPO_PATH/]REPO.git •$ git clone git://github.com/schacon/grit.git git:// •$ git clone https://SERVER/USER/REPO.git •$ git clone https://github.com/schacon/grit.git https:// •$git clone ssh://USER@SERVER/REPO.git •$git clone ssh://developer@dev.xamin.ir/native.gitssh:// 21
  • 22. ssh Example • cd ~/.ssh Check for SSH keys • $ls • $mkdir key_backup Backup and remove existing SSH keys • $mkdir key_backup • cp id_rsa* key_backup • rm id_rsa* • ssh-keygen -t rsa -C "your_email@youremail.com" • Enter path and pass phrase Generate a new SSH key • Done! Now, you can clone the repository on git server. Send “id_rsa.pub ” to the SERVERS’s administrator 22
  • 23. • File status life cycle – Add – Commit – Remove Add/Commit (status) GitInstall Git repo add/ commit Diff/log Remote Branch tag – Remove – Rename 23
  • 24. • File status life cycle Add/Commit (status) commitUntracked unmodifide modifide Staged Tracking files GitInstall Git repo add/ commit Diff/log Remote Branch tag 24
  • 25. • File status life cycle Add/Commit (status) commitUntracked unmodifide modifide Staged Tracking files GitInstall Git repo add/ commit Diff/log Remote Branch tag Add the file • You can remove the files from tracking/unmodified stage, too 25
  • 26. • File status life cycle Add/Commit (status) commitUntracked unmodifide modifide Staged Tracking files GitInstall Git repo add/ commit Diff/log Remote Branch tag Edit the file Add the file 26
  • 27. • File status life cycle Add/Commit (status) commitUntracked unmodifide modifide Staged Tracking files GitInstall Git repo add/ commit Diff/log Remote Branch tag Edit the file Add the file Staged the file 27
  • 28. • File status life cycle Add/Commit (status) commitUntracked unmodifide modifide Staged Tracking files GitInstall Git repo add/ commit Diff/log Remote Branch tag Commit file Edit the file Add the file Staged the file 28
  • 29. • File status life cycle Add/Commit (status) commitUntracked unmodifide modifide Staged Tracking files GitInstall Git repo add/ commit Diff/log Remote Branch tag Commit file Edit the file Add the file Staged the file Commit 29
  • 30. • File status life cycle – getting the file status: • $git status Add/Commit (status) GitInstall Git repo add/ commit Diff/log Remote Branch tag – Notice to: • Untracked files • Nothing to commit (working directory clean) • Changed but not updated • Changes to be committed 30
  • 31. • File status life cycle – getting the file status: • $git status Add/Commit (status) GitInstall Git repo add/ commit Diff/log Remote Branch tag – Notice to: • Untracked files • Nothing to commit (working directory clean) • Changed but not updated • Changes to be committed 31
  • 32. Add/Commit (commands) • Add files: – $git add your_file_or_directory – Multipurpose add: 1)begin tracking new files, 2)stage files, … Track new file • $vim README $git status • $ git add README $ git status • $vim benchmarks.rb $ git status • $ git add benchmarks.rb $ git status Staging modified files: 32
  • 33. Add/Commit (commands) • Commit: – $git commit (It opens vi to add message) – $git commit –m “your-message-goes-here” – $git commit –a –m “your-message-goes-here” (Skip staged area) • Remove – $git rm <file_name> (Remove from git repo) – $git rm --cached <your_file> (Remove from tracking files) • Rename: – $git mv <from_file> <to_file> 33
  • 34. Add/Commit(Undo) • Committing (Changing the last commit) – $git commit -m 'initial commit' – $git add <forgotten_file> – $ git commit --amend • Un-staging a staged file (Notice: status)• Un-staging a staged file (Notice: status) – $git reset HEAD <filename> • Un-modifying a modified file (Notice: status) – $git checkout -- <filename> • Deleted and overwritten commits are recoverable! 34
  • 35. Dot(!) gitignore • Ignoring: – A class of files that you don’t want Git to automatically add or even show you as being untrackeduntracked – .gitignore: listing all patterns that should be ignored • Ignoring files: – $ cat .gitignore • The rules 35
  • 36. Dot(!) gitignore • The rules – The blank lines or lines starting with # are ignored. – To specify a directory, end your patterns with “/” – Negate a pattern by “!” – “*” matches zero or more characters – [abc] matches any character inside the brackets– [abc] matches any character inside the brackets – “?” matches a single character • Example: – *~ (Ignore the temp files of Emacs) – build/ # (Ignore all of the files in the build directory ) – doc/*.txt # (Ignore doc/notes.txt, but not doc/server/arch.txt) – *.a # (Ignore the files which ends with .a) – !lib.a # (but do track lib.a, even though you're ignoring .a files) – /TODO # (Only ignore the root TODO file, not subdirectory /TODO) 36
  • 37. diff • We uses this command to: – know what is changed, not just which files were changed (It is not same as “git status” command) – answer these two questions: • What have you changed but not yet staged? • What have you staged that you are about to commit? – show the exact lines which are added and removed GitInstall Git repo add/ commit Diff/log Remote Branch tag – show the exact lines which are added and removed • To see what is modified but not it is not staged : – $git diff (compares working directory with staging area) • To see what is staged but is not committed: – $git diff --cached – $git diff --staged 37
  • 38. log • To Show commits on project reversely! – $git log • Each part of the ‘log’ command’s output contains: Sha1, Author’s Name and Email, Date of commit, and the Commit Message commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 Author: Scott Chacon <schacon@gee-mail.com> Date: Sat Mar 15 16:40:33 2008 -0700 removed unnecessary test code 38
  • 39. log… • To Show commits on project reversely! – $git log • Each part of the ‘log’ command’s output contains: Sha1, Author’s Name and Email, Date of commit, and the Commit Message • Options: – -p : Shows diff– -p : Shows diff – -<#n>: shows n-th last commits – --stat: shows statics for files modified in each commit: 1 files changed, 1 insertions(+), 1 deletions(-) – --pretty: The output format • =Oneline • =Short/full/fuller • =format :"%h %s" $ git log --since=2.weeks $ git log --pretty="%h - %s" --author=gitster --since="2008- 10-01" --before="2008-11-01" --t/ 39
  • 40. Log options description • -p: Show the patch introduced with each commit. • --stat: Show statistics for files modified in each commit. • --shortstat: Display only the changed/insertions/deletions line from the -- stat command. • --name-only: Show the list of files modified after the commit information. • --name-status: Show the list of files affected with added/modified/deleted information as well.information as well. • --abbrev-commit: Show only the first few characters of the SHA-1 checksum instead of all 40. • --relative-date: Display the date in a relative format (for example, “2 weeks ago”) instead of using the full date format. • --graph: Display an ASCII graph of the branch and merge history beside the log output. • --pretty: Show commits in an alternate format. Options include oneline, short, full, fuller, and format (where you specify your own format). 40
  • 41. Log format options • %H Commit hash • %h Abbreviated commit hash • %T Tree hash • %t Abbreviated tree hash • %P Parent hashes • %p Abbreviated parent hashes • %an Author name• %an Author name • %ae Author e-mail • %ad Author date (format respects the –date= option) • %ar Author date, relative • %cn Committer name • %ce Committer email • %cd Committer date • %cr Committer date, relative • %s Subject 41
  • 43. Remotes … • Showing your remotes – $ git remote – $ git remote –v (To show url) GitInstall Git repo add/ commit Diff/log Remote Branch tag $ git clone git:// github.com/schacon/ticgit.git$ git clone git:// github.com/schacon/ticgit.git $cd ticgit $git remote origin $ git remote -v origin git://github.com/schacon/ticgit.git koke git://github.com/koke/grit.git 43
  • 44. Remotes … • Showing your remotes – $ git remote – $ git remote –v (To show url) • Adding Remote Repositories(users repo) – $git remote add [shortname] [url] GitInstall Git repo add/ commit Diff/log Remote Branch tag – $git remote add [shortname] [url] $ git remote add pb git://github.com/paulboone/ticgit.git $ git remote -v origin git://github.com/schacon/ticgit.git pb git://github.com/paulboone/ticgit.git 44
  • 45. Remotes … • Showing your remotes – $ git remote – $ git remote –v (To show url) • Adding Remote Repositories(users repo) – $git remote add [shortname] [url] GitInstall Git repo add/ commit Diff/log Remote Branch tag – $git remote add [shortname] [url] • Fetching from user repo – $git fetch [remote-name] (no merge ) • Pulling from repo: (git clone automatically track master branch) – $git pull [remote-name] [branch-name] (Auto merge ) 45
  • 46. Remotes … • Pushing to Your Remotes – $ git push [remote-name] [branch-name] • Inspecting a Remote – $git remote show <remote-name>– $git remote show <remote-name> • Removing and Renaming Remotes (Changes your remote branch name, locally) – $git remote rename <prev_name> <new_name> – $git remote rm <branch_name> 46
  • 47. Tag • purposes – tag specific points in history as being important – mark release points • Tags Types – Lightweight GitInstall Git repo add/ commit Diff/log Remote Branch tag – Lightweight • it’s just a pointer to a specific commit • Just like a branch that doesn’t change – Annotated (recommended) • stored as full objects in the Git database • They’re checksummed • contain the tagger name, e-mail, and date • have a tagging message • can be signed and verified with GNU Privacy Guard(GPG) 47
  • 48. Tag… • Verifying a Signed Tag – need the signer’s public key in your keyring – If don’t have the signer’s public key: “could not verify the tag” • Sharing Tags – “git push” command doesn’t transfer tags to remote servers 48
  • 49. Tag… • List your tags – $ git tag • Search a pattern in the tags – $ git tag -l 'v1.4.2.*‘ • Lightweight tags: – $git tag <Your_Tag> – $git show <Your_Tag> (To show no more info) • Annotated tags: – git tag -a <Your_Tag> -m ‘<Tag_Message>’ – $git show <Your_Tag> (To show commit too) 49
  • 50. Tag… • Signed tags: – $git tag -s <Your_Tag> -m ‘<Tag_Message>’ – $git show <Your_Tag> (To show GPG sign too) • Verifying a signed tag – $git tag -v <Your_Tag>– $git tag -v <Your_Tag> • Tagging Later(Tag a specific commit) – $git tag -a <Your_Tag> <commit_checksum> (or part of it!) • Sharing Tags – $git push <remote-name> <Your_Tag> – $git push <remote-name> --tags (To push all tags) 50
  • 51. Some tips & tricks • Bach shell completion: – Find file GitDir/contrib/completion/git-completion.bash – For your user, copy it to home directory – For all user, copy it to /etc/bash_completion.d/– For all user, copy it to /etc/bash_completion.d/ – add it to your .bashrc file • Git Aliases – $git config --global alias <your-Alias> <command> – $git config --global alias.ci commit 51
  • 52. Branch You can have different versions of your source code! GitInstall Git repo add/ commit Diff/log Remote Branch tag 52
  • 53. Branch… • Every indexed file in stage area is a blob! • Every commit has a tree of blobs GitInstall Git repo add/ commit Diff/log Remote Branch tag 53
  • 54. Branch… • Every indexed file in stage area is a blob! • Every commit has a tree of blobs GitInstall Git repo add/ commit Diff/log Remote Branch tag 54
  • 55. Branch… • Every indexed file in stage area is a blob! • Every commit has a tree of blobs GitInstall Git repo add/ commit Diff/log Remote Branch tag 55
  • 56. What a Branch Is… 56
  • 57. What a Branch Is… $ git branch testing 57
  • 58. What a Branch Is… A special pointer called HEAD to know what branch you’re currently on. 58
  • 59. What a Branch Is… $ git checkout testing 59
  • 60. What a Branch Is… $ git commit -m 'made a change' 60
  • 61. What a Branch Is… $ git checkout master 61
  • 62. What a Branch Is… $ git commit -m 'made other changes' 62
  • 63. Basic Branch Commands AddAdd CommitCommit Remote repo Working directory Staging area Local repo PushPush FetchFetch Check outCheck out PullPull MergeMerge 63
  • 64. Basic Branch Commands • List the current branches: $git branch [-v] • Create a new branch: $git branch <New_Branch> • Change to a branch: $git checkout <Your_Branch> • Create & change to a new branch: $git checkout –b <Your_Branch> • Delete a branch: $git checkout –d <Your_Branch> • Merge the branch into current branch: $git merge <Your_Branch> • List current merged branches: $ git branch --merged • List the non-merged branches: $ git branch --no-merged • List all of local and remote branches: $git branch –a • List all of remote tracking branches: $git branch –r 64
  • 65. Branch merging The branch story(!) case study: 1- Do work on a web site. 2- Create a branch for a new story you’re working on. 3- Do some work in that branch. you’ll receive a call that another issue is critical and you need a hotfix. You’ll do the following: 1- Create a branch to add the hotfix. 2- After it’s tested, merge the hotfix branch, and push to production. 3- Switch back to your original story and continue working. 65
  • 66. Branch merging … 1- Do work on a web site. 66
  • 67. Branch merging … 1- Do work on a web site. 2- Create a branch for a new story you are working on: $git checkout -b iss53 67
  • 68. Branch merging … 1- Do work on a web site. 2- Create a branch for a new story you are working on: $git checkout -b iss53 3- Do some work in that branch:3- Do some work in that branch: $vim index.html $git commit -a -m 'added a new footer [issue 53] ' 68
  • 69. Branch merging … 1- Do work on a web site. 2- Create a branch for a new story you are working on: $git checkout -b iss53 3- Do some work in that branch:3- Do some work in that branch: $vim index.html $git commit -a -m 'added a new footer [issue 53] ‘ Another critical issue, and you need a hotfix! 69
  • 70. Branch merging … Another critical issue, and you need a hotfix! 1- Create a branch to add the hotfix: $ git checkout master $ git checkout -b 'hotfix' $ vim index.html $ git commit -a -m 'fixed the broken email address' 70
  • 71. Branch merging … Another critical issue, and you need a hotfix! 1- Create a branch to add the hotfix: $ git checkout master $ git checkout -b 'hotfix' $ vim index.html $ git commit -a -m 'fixed the broken email address‘ 2- After it’s tested, merge the hotfix branch, and push to production: $git checkout master $git merge hotfix 71
  • 72. Branch merging … Another critical issue, and you need a hotfix! 1- Create a branch to add the hotfix: $ git checkout master $ git checkout -b 'hotfix' $ vim index.html $ git commit -a -m 'fixed the broken email address‘ 2- After it’s tested, merge the hotfix branch, and push to production: $git checkout master $git merge hotfix 3- Switch back to your original story and continue working: $git branch -d hotfix $ git checkout issue 53 $ vim index.html $ git commit -a –m 'finished issue 53' 72
  • 73. Branch merging … • And now you want to merge issue 53: $git checkout master $git merge iss53 • What does the ‘merge’ command do? 1) It comes back to the common ancestor of branches1) It comes back to the common ancestor of branches 2) It creates a new snapshot from the last commit of branches 3) It creates a new commit point on master branch (C6) 4) It merges branches into the new commit point 73
  • 74. • what if conflicts happen: – $git merge iss53 Merge conflicts $git merge iss53 #Auto-merging index.html #CONFLICT (content): Merge conflict in index.html#CONFLICT (content): Merge conflict in index.html #Automatic merge failed; fix conflicts and then commit the result 74
  • 75. • what if conflicts happen: – $git merge iss53 • Which files unmerged? – $git status Merge conflicts [master*]$ git status[master*]$ git status #index.html: needs merge # On branch master # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # unmerged: index.html 75
  • 76. • what if conflicts happen: – $git merge iss53 • Which files unmerged? – $git status • Vi files with confilict: Merge conflicts <<<<<<< HEAD:index.html <div id="footer">contact : email.support@github.com</div> ======= <div id="footer"> please contact us at support@github.com </div> >>>>>>> iss53:index.html 76
  • 77. • what if conflicts happen: – $git merge iss53 • Which files unmerged? – $git status • Vi files with confilict: Merge conflicts Headiss53 <<<<<<< HEAD:index.html <div id="footer">contact : email.support@github.com</div> ======= <div id="footer"> please contact us at support@github.com </div> >>>>>>> iss53:index.html 77
  • 78. • what if conflicts happen: – $git merge iss53 • Which files unmerged? – $git status • Vi files with confilict: – Replace the conflict with one of the options, or merge them Merge conflicts – Replace the conflict with one of the options, or merge them together: <div id="footer"> please contact us at support@github.com </div> – And Then: $git add $git status $git commit 78
  • 84. Remote/Branch • Push to a Branch on Remote – $git push <remote-name> <local-branch> (push on tracking branch) – $git push <remote-name> <local-branch>:<remote-branch> • Receive from Remote Branch• Receive from Remote Branch – $git fetch <remote-name> – $ git merge <remote-name>/<remote-branch> • Delete a Remote Branches – $git push <remote-name> :<remote-branch> • Tracking a Branch on Remote: – $ git checkout --track (remote-name)/(branch-name) – $git checkout –b <local-branch> <remote-name>:<remote-branch>84
  • 85. gitk! •a graphical git Repository browser –$cd YOUR_GIT_REPO_DIR –$gitk 85
  • 86. Ref • The main reference: https://git-scm.com Special Thanks to ITRC 86