VERSION CONTROL SYSTEM git
ECE 650 - REZA BABAEE
LEARNING OBJECTIVES
▸ Explain what a version control system (VCS) is
▸ Identify git and its commands as a VCS
▸ Apply git commands to manage the assignments
WHAT IS VERSION (REVISION) CONTROL SYSTEM
▸ A system for managing changes to documents, programs, web pages,…
▸ Maintains a revision history of changes to the document
▸ Maintains multiple versions of a document
▸ Enables multiple users to collaborate on a common collection of documents
▸ There are many revision control systems available
▸ rcs, cvs, subversion, mercurial
▸ git
git HISTORY
▸ Developed by the Linux development community
▸ Linus Torvalds, 2005
▸ Initial goals
▸ Speed
▸ Simple design
▸ Strong support for non-linear development (thousands of parallel branches)
▸ Fully distributed
▸ Able to handle large projects like the Linux kernel efficiently (speed and data size)
git RESOURCES
▸ From the command line
▸ git help to get a list of commands
▸ git help <cmd>
▸ where <cmd> is a git command (e.g., add, commit, fetch, merge)
▸ On-line book
▸ https://git-scm.com/book/en/v2
▸ Tutorial
▸ https://git-scm.com/docs/gittutorial
▸ Interactive Tutorial on GitHub
▸ https://try.github.io/
git commit
▸ A snapshot of all the files in the directory
▸ Lightweight copy-and-paste
▸ Only stores the changes from one version to another (called delta)
▸ git keeps a history of commits
▸ git commit <file> | -a (all files) -m “<message>”
SNAPSHOTS, NOT DIFFERENCESdifferences
snapshots
git add
▸ Making git keep track of a file/directory (so-called staging the file/directory)
▸ git add <filename> (not required if using -am in git commit)
git branch
▸ Pointers to specific commits
▸ A branch essentially says "I want to include the work of this commit and all parent commits.”
▸ git branch <name of branch>
▸ git checkout -b <name of branch>
git merge
▸ Combining the work from two different branches
▸ The workflow so far:
▸ Branch off
▸ working on a feature, fixing bugs, etc.
▸ Combine back in
▸ Merging creates a special commit with two unique parents
▸ git merge <name of the branch to be merged>
git merge - Example
▸ git checkout master
▸ git merge dumbidea
▸ git merge iss91v2
DISTRIBUTED VERSION CONTROL SYSTEM
▸ So far working on a local directory
▸ Making VCS distributed
▸ backup!
▸ Social coding!
▸ Remote repositories: copies of your files on other computers
▸ Free git servers: gitHub, gitLab, bitbucket, phabricator, …
git clone
▸ Creates a local copy of a remote repository
▸ git clone [—recursive] <username>@<remote address> <name-of-local-directory>
▸ Requires
▸ ssh: uses a ssh-key for authentication or
▸ https: asks for username/password on the a CLI
git status
▸ Gives the status of your git repository
▸ Untracked files
▸ Changes that are not committed
▸ Your current local branch
▸ Changes between the local and the remote branch
▸ The remote and the remote branch <remote-name>/<remote-branch>
git pull
▸ Downloads the remote repository (so-called fetching), and merges the current local branch into the remote branch
▸ git pull (there is a remote added to the git once you cloned, so git knows where to fetch from, you can change it)
git push
▸ Uploads the local branch into the remote branch
▸ All people having access to the remote branch can see your changes
▸ git push
COMMON git WORKFLOW
▸ init or clone
▸ Create an empty repo or make a local copy of a remote repo
▸ Edit some files, create and modify content
▸ add (or stage)
▸ mark changes to be combined into a commit
▸ a commit is a unit of change, a new version
▸ each commit has a globally unique name (i.e., 029389678201859fd6838c8b6c059edd0f17efcf)
▸ Commit
▸ create a commit based on identified changes
▸ push
▸ propagate changes to remote repo
▸ fetch or pull
▸ download changes from remote repo
TIPS - COMMITS
▸ Commit your changes after each unit of work
▸ Use appropriate messages for your commits
▸ Separate subject from body with a blank line
▸ Limit the subject line to 50 characters
▸ Capitalize the subject line
▸ Do not end the subject line with a period
▸ Use the imperative mood in the subject line
▸ Wrap the body at 72 characters
▸ Use the body to explain what and why vs. how
TIPS - BRANCHING
▸ Branch early branch often next version to replace (merge into) master
▸ master – stable version
▸ only stable, well-tested commit
▸ develop – development version
▸ next version to replace (merge into) master
▸ topic – experimental bleeding edge
▸ test stuff out before merging into develop
SUMMARY
▸ What is a version control system?
▸ What features git provides for VCS?
▸ git commands
▸ The tips on git commits and branching