VERSION CONTROL SYSTEMS - GIT Boyu Zhang Research Computing Purdue University 1
OUTLINE Introduction and vocabulary Basic git model Basic git workflow Git clients Git branching model Summary 2
VERSION CONTROL WHAT IS VERSION CONTROL A system that records changes to a file or set of files over time so that you can recall specific versions later Users do not need to make duplicates of files, you can go back in time for files that are under version control You are using version control without noticing! Copy files into another directory in your local/remote workstation 3
VERSION CONTROL LOCAL VERSION CONTROL SYSTEMS A system that records changes to a file or set of files over time so that you can recall specific versions later Users do not need to make duplicates of files, you can go back in time for files that are under version control Version control in different forms Local version control systems rcs A simple database that keeps all the changes to files Everything is stored locally on your workstation If the disk fails, you are out of luck Difficult for collaborations among developers 4
VERSION CONTROL CENTRALIZED VERSION CONTROL SYSTEMS A system that records changes to a file or set of files over time so that you can recall specific versions later Users do not need to make duplicates of files, you can go back in time for files that are under version control Version control in different forms Centralized version control systems subversion A single server stores all the versioned files Multiple clients that check out files Solved the issues of collaboration The central server is the single point of failure 5
VERSION CONTROL DISTRIBUTED VERSION CONTROL SYSTEMS A system that records changes to a file or set of files over time so that you can recall specific versions later Users do not need to make duplicates of files, you can go back in time for files that are under version control Version control in different forms Distributed version control systems git A single or multiple servers store all files Clients have their own local repository If the server dies, any of the clients repositories can be copied to the server to restore it 6
ONLINE LEARNING RESOURCES BOOKS, TUTORIALS, CHEAT SHEETS ETC Free online book: https://git-scm.com/book/ Git website: https://git-scm.com Git tutorials: https://www.atlassian.com/git/tutorials/ Learn git online: http://pcottle.github.io/learngitbranching/ Git cheat sheet: https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf http://ndpsoftware.com/git-cheatsheet.html Git hosts: https://github.com https://bitbucket.org https://github.rcac.purdue.edu (for Purdue only) 7
BASIC GIT MODEL DISTRIBUTED Clients fully mirror the repository Every clone is a full back up clone creates a copy of the repository to one s local machine 8
BASIC GIT MODEL SNAPSHOTS, NOT DIFFERENCES Treats its data (version controlled files) as a stream of snapshots Every version is a snapshot of all files (with optimizations) 9
BASIC GIT MODEL NEARLY EVERY OPERATION IS LOCAL Most operations only need local files and resources to operate Only a few operations interact with the remote repository (e.g., clone, pull, push) 10
BASIC GIT MODEL THREE LOCAL SECTIONS OF A GIT PROJECT Working directory A single checkout of one version of the project Staging area Stores information on what will go into your next commit Git directory Stores the repo metadata and database Files are ready to be pushed to remote repo Unmodified/modified Files Staged Files Basic git workflow Modify files in your working directory Stage files, adding snapshots to the staging area Commit files, take the files in the staging area and store them permanently to the git directory, which are ready to be pushed to the remote git repo 11 Committed Files
BASIC GIT MODEL GIT FILE LIFECYCLE Untracked the file is not under version control Unmodified the file is under version control, with no edit Modified the file is under version control, with some edits Staged the file is under version control, ready to commit Check the status of your files: git status 12
BASIC GIT WORKFLOW CREATE OR CLONE, MODIFY, COMMIT, PUSH Create a new git repository from any git host servers 13
BASIC GIT WORKFLOW CREATE OR CLONE, MODIFY, COMMIT, PUSH Clone a local copy of a repo from an already existing repo 14
BASIC GIT WORKFLOW CREATE OR CLONE, MODIFY, COMMIT, PUSH Clone a local copy of a repo from an already existing repo git clone url [dir] 15
BASIC GIT WORKFLOW CREATE OR CLONE, MODIFY, COMMIT, PUSH Check the status of your personal repo 16
BASIC GIT WORKFLOW CREATE OR CLONE, MODIFY, COMMIT, PUSH Check the status of your personal repo git status It is a good habit to do this often! 17
BASIC GIT WORKFLOW CREATE OR CLONE, MODIFY, COMMIT, PUSH Make your changes vim README.md git status 18
BASIC GIT WORKFLOW CREATE OR CLONE, MODIFY, COMMIT, PUSH Make your changes vim README.md git status 19
BASIC GIT WORKFLOW CREATE OR CLONE, MODIFY, COMMIT, PUSH Commit your changes The first time we ask a file to be tracked, and every time before we commit a file we must add it to the staging area git add README.md git commit m commit message 20
BASIC GIT WORKFLOW CREATE OR CLONE, MODIFY, COMMIT, PUSH Commit your changes The first time we ask a file to be tracked, and every time before we commit a file we must add it to the staging area 21
BASIC GIT WORKFLOW CREATE OR CLONE, MODIFY, COMMIT, PUSH Push your changes to remote (the server) Good practice: Add and commit your changes to your local repo Pull from remote to get most recent changes (fix conflicts if necessary, add and commit again to you local repo) Push your changes to the remote repo 22
BASIC GIT WORKFLOW CREATE OR CLONE, MODIFY, COMMIT, PUSH Push your changes to remote (the server) Good practice: Add and commit your changes to your local repo Pull from remote to get most recent changes (fix conflicts if necessary, add and commit again to you local repo) Push your changes to the remote repo git pull origin master git push origin master 23
BASIC GIT WORKFLOW CREATE OR CLONE, MODIFY, COMMIT, PUSH In theory, every thing should work perfectly! In reality 24
BASIC GIT WORKFLOW CREATE OR CLONE, MODIFY, COMMIT, PUSH In theory, every thing should work perfectly! In reality any thing can go wrong! How to resolve conflicts How to go back to the previous commits How to use the branching model to mange development, bug fix, and release How to hide you current work without committing it 25
GIT CLIENTS SOURCETREE 26
GIT CLIENTS COMMAND LINE 27
GIT BRANCHING MODEL COLLABORATIVE PROJECTS MANAGEMENT Main branches Master Production-ready state Develop The latest delivered changes for the next release Supporting branches Feature Branch off and merge into develop branch Release Branch off develop and merge into develop and master Hotfixes Branch off master and merge into develop and master 28 V. Driessen: A Successful Git Branching Model, h;p://nvie.com/posts/a-successful-git-branching-model/
TAKE AWAY SIX GIT COMMANDS TO GET STARTED git clone url [dir] git status git add file git commit m commit message git pull origin master git push origin master 29