An introduction to version control systems with Git
Transcript of An introduction to version control systems with Git
![Page 1: An introduction to version control systems with Git](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e67c91dda2206f47568e2b/html5/thumbnails/1.jpg)
An introduction to version control systems
with Git
![Page 2: An introduction to version control systems with Git](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e67c91dda2206f47568e2b/html5/thumbnails/2.jpg)
● Version control systems record changes to a file or set of
files over time so that you can recall specific versions later
● Many systems have risen to popularity over the years
○ RCS
○ CVS
○ Subversion
● We will focus on Git
Version control systems
2
![Page 3: An introduction to version control systems with Git](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e67c91dda2206f47568e2b/html5/thumbnails/3.jpg)
● These systems help with:
○ Tracking changes
○ Short and long term undo
○ Backup and restore
○ Synchronization
○ Collaboration
Why use version control?
3
![Page 4: An introduction to version control systems with Git](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e67c91dda2206f47568e2b/html5/thumbnails/4.jpg)
Local version control systems
4
![Page 5: An introduction to version control systems with Git](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e67c91dda2206f47568e2b/html5/thumbnails/5.jpg)
Centralized version control systems
5
![Page 6: An introduction to version control systems with Git](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e67c91dda2206f47568e2b/html5/thumbnails/6.jpg)
Distributed version control systems
6
![Page 7: An introduction to version control systems with Git](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e67c91dda2206f47568e2b/html5/thumbnails/7.jpg)
● Modify files in your working directory● Stage the files, adding snapshots to your staging area● Commit your changes to your local copy of the repository
The basic Git workflow
7
![Page 8: An introduction to version control systems with Git](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e67c91dda2206f47568e2b/html5/thumbnails/8.jpg)
● Git does not necessary keep track of all files in your working directory
The lifecycle of a file in Git
8
![Page 9: An introduction to version control systems with Git](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e67c91dda2206f47568e2b/html5/thumbnails/9.jpg)
Example repository
9
![Page 10: An introduction to version control systems with Git](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e67c91dda2206f47568e2b/html5/thumbnails/10.jpg)
● Set your identity
○ $ git config --global user.name "John Doe"
○ $ git config --global user.email [email protected]
● Set other configuration options
○ $ git config --global color.ui true
● Get help
○ $ git help verb
Gitting started
10
![Page 11: An introduction to version control systems with Git](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e67c91dda2206f47568e2b/html5/thumbnails/11.jpg)
● $ git init
● Creates a new (empty) repository in the current directory
Creating a new repository
11
![Page 12: An introduction to version control systems with Git](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e67c91dda2206f47568e2b/html5/thumbnails/12.jpg)
● For this class, your instructor will create a repository for
you, you will just need to copy it from GitHub to your
computer using the following command:
● $ git clone repository
○ Creates a copy of repository in the current directory
Copying a repository
12
![Page 13: An introduction to version control systems with Git](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e67c91dda2206f47568e2b/html5/thumbnails/13.jpg)
● As you work, you will create new files and modify existing
files, when you are satisfied with your changes, you can
stage them for commit with:
● $ git add file_pattern
Staging files
13
![Page 14: An introduction to version control systems with Git](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e67c91dda2206f47568e2b/html5/thumbnails/14.jpg)
● Commits create a new version in the repository
● Include a commit message describing the new version
● $ git commit -m msg
Committing changes
14
![Page 15: An introduction to version control systems with Git](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e67c91dda2206f47568e2b/html5/thumbnails/15.jpg)
● $ git status
● Reports:
○ Files in the working directory that are not tracked
○ File modifications not yet staged for commit
○ File additions and modifications staged for commit
Checking working directory status
15
![Page 16: An introduction to version control systems with Git](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e67c91dda2206f47568e2b/html5/thumbnails/16.jpg)
● $ git log
● Lists commits made to the current repository
Overviewing commit history
16
![Page 17: An introduction to version control systems with Git](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e67c91dda2206f47568e2b/html5/thumbnails/17.jpg)
● It may be handy to see exactly how files changed
● $ git diff
○ Shows modifications not yet staged for commit
● $ git diff commit_id
○ Show changes since the commit specified
● $ git diff commit_id1 commit_id2
○ Show changes between two commits
Handy command - comparing versions
18
![Page 18: An introduction to version control systems with Git](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e67c91dda2206f47568e2b/html5/thumbnails/18.jpg)
● … presents only a brief overview of Git
○ Further topics:
■ branching
■ rebasing
■ tagging
■ …
● Further resources:
○ https://git-scm.com/book/en/v2
○ http://gitimmersion.com/
What we've covered here...
19