SlideShare une entreprise Scribd logo
1  sur  86
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

Introduction to Git
Introduction to GitIntroduction to Git
Introduction to GitAmit Mathur
 
Gitting out of trouble
Gitting out of troubleGitting out of trouble
Gitting out of troubleJon Senchyna
 
Docking postgres
Docking postgresDocking postgres
Docking postgresrycamor
 
Data Publication and Discovery with Globus
Data Publication and Discovery with GlobusData Publication and Discovery with Globus
Data Publication and Discovery with GlobusGlobus
 
Git hub ppt presentation
Git hub ppt presentationGit hub ppt presentation
Git hub ppt presentationAyanaRukasar
 
Software Packaging with RPM
Software Packaging with RPMSoftware Packaging with RPM
Software Packaging with RPMSchalk Cronjé
 
Docker Registry + Basic Auth
Docker Registry + Basic AuthDocker Registry + Basic Auth
Docker Registry + Basic AuthRemotty
 
Configure, Pack and Distribute: An RPM Creation Workshop
Configure, Pack and Distribute: An RPM Creation WorkshopConfigure, Pack and Distribute: An RPM Creation Workshop
Configure, Pack and Distribute: An RPM Creation WorkshopNovell
 
Software management in linux
Software management in linuxSoftware management in linux
Software management in linuxnejadmand
 
Introduction to Globus for System Administrators (GlobusWorld Tour - UMich)
Introduction to Globus for System Administrators (GlobusWorld Tour - UMich)Introduction to Globus for System Administrators (GlobusWorld Tour - UMich)
Introduction to Globus for System Administrators (GlobusWorld Tour - UMich)Globus
 
CASPUR Staging System II
CASPUR Staging System IICASPUR Staging System II
CASPUR Staging System IIAndrea PETRUCCI
 
Postgre sql linuxcontainers by Jignesh Shah
Postgre sql linuxcontainers by Jignesh ShahPostgre sql linuxcontainers by Jignesh Shah
Postgre sql linuxcontainers by Jignesh ShahPivotalOpenSourceHub
 
Smau Milano 2016 - Fabio Alessandro Locati
Smau Milano 2016 - Fabio Alessandro LocatiSmau Milano 2016 - Fabio Alessandro Locati
Smau Milano 2016 - Fabio Alessandro LocatiSMAU
 

Tendances (19)

Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Gitting out of trouble
Gitting out of troubleGitting out of trouble
Gitting out of trouble
 
Docking postgres
Docking postgresDocking postgres
Docking postgres
 
Data Publication and Discovery with Globus
Data Publication and Discovery with GlobusData Publication and Discovery with Globus
Data Publication and Discovery with Globus
 
Backups
BackupsBackups
Backups
 
Git hub ppt presentation
Git hub ppt presentationGit hub ppt presentation
Git hub ppt presentation
 
Software Packaging with RPM
Software Packaging with RPMSoftware Packaging with RPM
Software Packaging with RPM
 
Linux basic commands
Linux basic commandsLinux basic commands
Linux basic commands
 
Docker Registry + Basic Auth
Docker Registry + Basic AuthDocker Registry + Basic Auth
Docker Registry + Basic Auth
 
Configure, Pack and Distribute: An RPM Creation Workshop
Configure, Pack and Distribute: An RPM Creation WorkshopConfigure, Pack and Distribute: An RPM Creation Workshop
Configure, Pack and Distribute: An RPM Creation Workshop
 
RPM Packaging 101 (Old)
RPM Packaging 101 (Old)RPM Packaging 101 (Old)
RPM Packaging 101 (Old)
 
Software management in linux
Software management in linuxSoftware management in linux
Software management in linux
 
Introduction to Globus for System Administrators (GlobusWorld Tour - UMich)
Introduction to Globus for System Administrators (GlobusWorld Tour - UMich)Introduction to Globus for System Administrators (GlobusWorld Tour - UMich)
Introduction to Globus for System Administrators (GlobusWorld Tour - UMich)
 
CASPUR Staging System II
CASPUR Staging System IICASPUR Staging System II
CASPUR Staging System II
 
Postgre sql linuxcontainers by Jignesh Shah
Postgre sql linuxcontainers by Jignesh ShahPostgre sql linuxcontainers by Jignesh Shah
Postgre sql linuxcontainers by Jignesh Shah
 
Git Presentation
Git PresentationGit Presentation
Git Presentation
 
Smau Milano 2016 - Fabio Alessandro Locati
Smau Milano 2016 - Fabio Alessandro LocatiSmau Milano 2016 - Fabio Alessandro Locati
Smau Milano 2016 - Fabio Alessandro Locati
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Mini git tutorial
Mini git tutorialMini git tutorial
Mini git tutorial
 

En vedette (14)

1059
10591059
1059
 
SAFe-SA-Certificate
SAFe-SA-CertificateSAFe-SA-Certificate
SAFe-SA-Certificate
 
Tucson Prairie Dawgs Final Presentation
Tucson Prairie Dawgs Final PresentationTucson Prairie Dawgs Final Presentation
Tucson Prairie Dawgs Final Presentation
 
Tectonica de placas
Tectonica de placasTectonica de placas
Tectonica de placas
 
1 subida serra da groba 1 oficial
1 subida serra da groba 1 oficial1 subida serra da groba 1 oficial
1 subida serra da groba 1 oficial
 
Human BIOERAGROUP
Human BIOERAGROUP Human BIOERAGROUP
Human BIOERAGROUP
 
Adrian yANEZ
Adrian yANEZAdrian yANEZ
Adrian yANEZ
 
RAP Results7-6-16
RAP Results7-6-16RAP Results7-6-16
RAP Results7-6-16
 
QAI STC 2012 Plenary Keynote: Testing 3.0 - Pricing for Value
QAI STC 2012 Plenary Keynote: Testing 3.0 - Pricing for ValueQAI STC 2012 Plenary Keynote: Testing 3.0 - Pricing for Value
QAI STC 2012 Plenary Keynote: Testing 3.0 - Pricing for Value
 
Bermuda triangle
Bermuda triangleBermuda triangle
Bermuda triangle
 
AriZona Beverage Company sucess case
AriZona Beverage Company sucess caseAriZona Beverage Company sucess case
AriZona Beverage Company sucess case
 
UNIT 5: FOOD AND BEVERAGE OPERATIONS MANAGEMENT
UNIT 5: FOOD AND BEVERAGE OPERATIONS MANAGEMENTUNIT 5: FOOD AND BEVERAGE OPERATIONS MANAGEMENT
UNIT 5: FOOD AND BEVERAGE OPERATIONS MANAGEMENT
 
The Agile PMO PMI Pittsburgh Michael Nir
The Agile PMO PMI Pittsburgh Michael Nir The Agile PMO PMI Pittsburgh Michael Nir
The Agile PMO PMI Pittsburgh Michael Nir
 
Open DataFest III - 3.14.16 - Day One Afternoon Sessions
Open DataFest III - 3.14.16 - Day One Afternoon SessionsOpen DataFest III - 3.14.16 - Day One Afternoon Sessions
Open DataFest III - 3.14.16 - Day One Afternoon Sessions
 

Similaire à Git basics

Git 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGit 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGeoff Hoffman
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github Max Claus Nunes
 
Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An IntroductionBehzad Altaf
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configurationKishor Kumar
 
CSE 390 Lecture 9 - Version Control with GIT
CSE 390 Lecture 9 - Version Control with GITCSE 390 Lecture 9 - Version Control with GIT
CSE 390 Lecture 9 - Version Control with GITPouriaQashqai1
 
Learning git
Learning gitLearning git
Learning gitSid Anand
 
Git and github fundamental
Git and github fundamentalGit and github fundamental
Git and github fundamentalRajesh Kumar
 
git-and-bitbucket
git-and-bitbucketgit-and-bitbucket
git-and-bitbucketazwildcat
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthroughBimal Jain
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.comdropsolid
 
Version control with GIT
Version control with GITVersion control with GIT
Version control with GITZeeshan Khan
 

Similaire à Git basics (20)

Git 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGit 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using Git
 
git.ppt.pdf
git.ppt.pdfgit.ppt.pdf
git.ppt.pdf
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
390a gitintro 12au
390a gitintro 12au390a gitintro 12au
390a gitintro 12au
 
sample.pptx
sample.pptxsample.pptx
sample.pptx
 
Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An Introduction
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
 
GIT.pptx
GIT.pptxGIT.pptx
GIT.pptx
 
CSE 390 Lecture 9 - Version Control with GIT
CSE 390 Lecture 9 - Version Control with GITCSE 390 Lecture 9 - Version Control with GIT
CSE 390 Lecture 9 - Version Control with GIT
 
Git hub
Git hubGit hub
Git hub
 
Learning git
Learning gitLearning git
Learning git
 
Git 101
Git 101Git 101
Git 101
 
Git and github fundamental
Git and github fundamentalGit and github fundamental
Git and github fundamental
 
Git training v10
Git training v10Git training v10
Git training v10
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 
git-and-bitbucket
git-and-bitbucketgit-and-bitbucket
git-and-bitbucket
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
 
簡單介紹git
簡單介紹git簡單介紹git
簡單介紹git
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.com
 
Version control with GIT
Version control with GITVersion control with GIT
Version control with GIT
 

Dernier

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 

Dernier (20)

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

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