class: center, middle # CSCI-UA 480.10: OSSD
## Version Control Systems .author[ Instructor: Joanna Klukowska
] .license[ Unless noted otherwise all content is released under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). ] --- # Attribution Majority of the content of these slides has been adapted from two books: - [_Producing Open Source Software_](http://producingoss.com/) by Karl Fogel, distributed under [Creative Commons Attribution-ShareAlike 4.0 International License](http://producingoss.com/en/copyright.html) - [_ProGit_](https://git-scm.com/book/en/v2) by Scott Chacon and Ben Straub, distributed under [Creative Commons Attribution Non Commercial Share Alike 3.0 license](https://creativecommons.org/licenses/by-nc-sa/3.0/) --- # Version Control System (VCS) - what is a version control system (and don't say _GitHub_)? -- A _version control system_ (or _revision control system_) is a combination of technologies and practices for tracking and controlling changes to a project's files, in particular to source code, documentation, and web pages. (But is often used for projects that have nothing or little to do with code.) -- - why do we need version control? -- - what are some examples of version control systems ? -- - git, see [Wikipedia article](https://en.wikipedia.org/wiki/Git) - subversion (or Apache subversion, or SVN), see [Wikipedia article](https://en.wikipedia.org/wiki/Apache_Subversion) - Mercurial, see [Wikipedia article](https://en.wikipedia.org/wiki/Mercurial) - there are few other/older ones, but they are not used for any new projects --- class: middle __Show of hands:__ - Who feels comfortable using a version control system (git, or anything else)? - beginner - intermediate - expert - Who uses a version control system on a regular basis (for purposes other than class assignments)? - Who uses the terminal to _communicate_ with the version control system? (for example for making the course blog posts) --- # VCS Jargon - __repository__ -- A database in which changes are stored and from which they are published.
In centralized VCS, there is a single, master repository.
In decentralized VCS, each developer has their own repository, changes can be swapped back and forth between repositories arbitrarily. .left-column2[.center[
centralized VCS ]] .right-column2[.center[
decentralized VCS ]] --- # VCS Jargon - __clone__ -- To obtain one's own development repository by making a copy of the project's central repository. -- - __commit__ -- To make a change to the project; more formally, to store a change in the version control database in such a way that it can be incorporated into future releases of the project. "Commit" can be used as a verb or a noun. For example: "I just committed a fix for the server crash bug people have been re- porting on Mac OS X. Jay, could you please review the commit and check that I'm not misusing the allocator there?" -- - __commit message__ or __log message__ -- A bit of commentary attached to each commit, describing the nature and purpose of the commit. -- - __push__ -- To publish a commit to a (public) remote repository, from which others can incorporate it inot their copy of he project's code. In some VCS the remote repository is pre-determined, in others it is user specified. --- # VCS Jargon - __pull__ / update -- To incorporate changes/commits present in the remote repository into your own copy of the project. -- - __working copy__ or __working files__ -- A developer's private directory tree containing the project's source code files. In decentralized VCS, working copies and repositories are usually colocated, so the term "working copy" is less often used. Developers instead tend to say "my clone" or "my copy" or sometimes "my fork". -- - __diff__ -- A textual representation of a change. A diff shows which lines were changed and how, plus a few lines of surrounding context on either side. A developer who is already familiar with some code can usually read a diff against that code and understand what the change did, and often even spot bugs. --- # VCS Jargon - __branch__ -- A copy of the project, under version control but isolated so that changes made to the branch don't affect other branches of the project, and vice versa, except when changes are deliberately "merged" from one branch to another (see below). Branches are also known as "lines of development". Branches offer a way to keep different lines of development from interfering with each other. For example, a branch can be used for experimental development that would be too destabilizing for the main trunk. -- - __merge__ -- To copy a change from one branch to another. -- - __conflict__ -- What happens when two people try to make different changes to the same place in the code. All version control systems automatically detect conflicts, and notify at least one of the humans involved that their changes conflict with someone else's. It is then up to that human to resolve the conflict, and to communicate that resolution to the version control system. --- # Git - developed in 2005 by Linus Torvalds - mantained since then by [Junio Hamano](https://en.wikipedia.org/wiki/Junio_Hamano) - website: https://git-scm.com/ - repository: https://github.com/git/git - IRC: irc.freenode.net , channel #git --- # Working with a git repository
![Figure 6 from ProGit](https://git-scm.com/book/en/v2/images/areas.png) --- - installing git - make sure that you have environment setup for working with git in a terminal - configuring git - setup your name / user name / identifier `git config --global user.name "John Doe"` - setup your email address `git config --global user.email "John.Doe@worlds.net"` - setup your prefered text editor `git config --global user.editor vi` - cache your credentials for a few minutes, so you do not have to retype your username and password on every single push ` git config --global credential.helper cache` - check your current config `git config --list` --- - getting info about your repository (the local copy of it) - show the working tree status (information about what is staged, what is tracked/untracked) `git status` - show the list of all the commits (commit lot) in reverse chronological order `git log` - display the info about the remote repository `git remote show origin` --- # --- # Sources and Acknowledgements