Changes

Jump to navigation Jump to search

Workshop: Introduction to version control

202 bytes removed, 16:07, 19 September 2019
add workshop header template
{{Workshop header}}[[File:Poor_project_management.png|right|frame|Has this ever happened to you? No more, with version control!]] ''(Generally, this workshop is offered at least once a week on a rotating basis. Check the [http://designandbuildlab.com/?page_id=445/ Lab calendar] for up-to-date availability!)''
'''Version control''' is a technique for managing the complexity of a digital project - especially one which is done collaboratively.
== What is version control? ==
When a project is in its infancy, it is fairly straightforward to keep track of the files contained within; it can, however, become unmanageable very quickly - especially if revisions happen frequently. Version control can be imagined as a series of '''snapshots''' of a project's changes as time progresses; it effectively stores the entire history of the project. Each snapshot allows you to see exactly the state of the project at that time; you can travel back to any of these snapshots at any time.
A '''version control system''' (VCS) is a tool that handles all of this complexity: the repo itself, the snapshots, the remote(s), et al. There are many VCS's; the most popular is called '''[https://git-scm.com/downloads git]'''.
=== Why use version control? ===
The two advantages that version control provides:
# ''You are able to travel back in time to any point in a project and utilize it from that moment''; and
# ''Management of a collaborative project is streamlined''.
#''You are able to travel back in time to any point in a project and utilize it from that moment''; and#''Management of a collaborative project is streamlined''. == Utilizing version Control ===== Required tools === * A VCS - preferably '''[https://git-scm.com/downloads git]'''.* A web-based system to host your remotes.** [https://bitbucket.org/ Bitbucket] is recommended because it offers free private repos for small teams.** [https://github.com/ Github] is the most widely used web-based repository.* Git is accessed through the command line interface (CLI) of your choice:
**''Windows'': you can use Git Bash (which should install when you installed git) or PowerShell; Bash is preferred because it is nicely color-coded.
**''Linux/MacOS'': terminal (which is installed with the operating system).
=== Acquiring a repo ===
There are two main ways to work with a repo: create one yourself, or use someone else's.
==== I want to create one myself! ==== 
*If you are only going to be working on this repository locally, then:
*# In your CLI, navigate to the place you'd like to save the repo folder: <code>cd [path]</code>*# Create the repo folder: <code> mkdir [repository folder name]</code>*# Navigate into the repo folder: <code>cd [repository folder name</code>*# Initialize the repository: <code>git init</code>
*If instead, you are going to be working with a remote, then:
*# Create a new repo on your remote of choice.*# Locate and copy the url for the git remote. Typically, this is in the top-right corner of the repo's main web page.*# In your CLI, navigate to the place you'd like to save the repo folder: <code>cd [path]</code>*# Use the ''clone'' function of git to download a copy of the repo locally: <code>git clone [the_link_you_copied_in_step_2.git]</code>*# You can now begin working with your repo! ====I want to work with someone else's!====
==== I want to work with someone else's! ====
*This process is also simple: ''find'' a repo that you'd like to work with on a remote, and clone it onto your system:
*# Find a remote repository you'd like to work with.*# Locate and copy the url for the git remote. Typically, this is in the top-right corner of the repo's main web page.*# In your CLI, navigate to the place you'd like to save the repo folder: <code>cd [path]</code>*# Use the ''clone'' function of git to download a copy of the repo locally: <code>git clone [the_link_you_copied_in_step_2.git]</code>*# You can now begin working with your repo!
=== Working with a repo ===
==== Typical workflow ====
When working on a project ''locally'', your workflow will typically consist of the following:
 
#'''Modify''' files within the repository's folder (e.g. changing lines of code).
#'''Stage''' those changes: <code>git add [filename]</code>
#'''Commit''' those changes to the repository: <code>git commit -m "[a message describing the changes]"</code>
 
''If you have a remote set up'', then two steps bookend the workflow above:
 
#'''Pull''' any changes from the remote repository to your local copy: <code>git pull</code>
#'''Modify''' files within the repository's folder (e.g. changing lines of code).
#'''Push''' the new commit to the remote repository: <code>git push [remote name] [branch name]</code>
== Terminology ==
'''repository''': the location and contents of a project, including all version control information
'''branch''': a particular timeline of snapshots - the main branch is typically called "master"; other branches may be used to develop new features without risking the master branch's stability
== Common git commands ==
{| class="wikitable sortable mw-collapsible"
!Command
|}
== Sample git workflow ==
The typical git workflow will depend on whether you're working on a personal repository or on a team.
{| class="wikitable"
! style="text-align:center;"|Simple personal workflow:||Team workflow:
|-
|[[File:Gitworkflow.png|600px]]||[[File:Git_workflow_team.gif|400px]]
|}
== External Links ==
Git's [https://git-scm.com/docs git's own reference manual]

Navigation menu