Lesson 2: Version Control

Intro to Version Control

A version control system provides an automatic way to track changes in software projects, giving creators the power to view previous versions of files and directories, develop speculative features without disrupting the main development, securely back up the project and its history, and collaborate easily and conveniently with others.

In addition, using version control also makes deploying production websites and web applications much easier.

As a result, fluency in at least one version control system is an essential component of being a developer.

What is Git?

Version control has evolved considerably over the years. The family line leading to Git includes programs called RCS, CVS, and Subversion, and there are many current alternatives as well, including Perforce, Bazaar, and Mercurial. Once you commit to a VCS its hard to switch to another. The most popular VCS right now is Git. Its open source and many sites like Github and Bitbucket support it.

Why is it used and when should it be used?

Git allows groups of people to work on the same documents (often code) at the same time, and without stepping on each other's toes. It's a distributed version control system. It allows people to collaborate on different features at the same time, on the same code base, without disrupting the other person's workflow.

If you are working in a team, then its very important to use a VCS, like Git. When merging code, conflicts can arise.

If you are working solo on a project, its still good to think about using Git, because your project may expand and others could join later.

Git Commit messages guideline

You should always start the message with an infinitive verb and keep the message short / brief, direct and related to the changes.

The idea of the commit is register the changes made on the code / file. Actions like:

  • Rename a function / file

  • Add a new function / file

  • Delete a function / file

  • Add a function / file

You don't have to commit every single line of code that you create, this will consume too much time and won't be a good cost / benefit. The idea is commit every time that you have meaningful enough changes.

Git as a Servicess

Github

We’ll start by pushing our project up to Github, a site designed to facilitate collaboration with Git repositories.

For repositories that are publicly available, GitHub is free, so we’ll plan to make our website’s repo public to take advantage of this.

GitHub charges for private repositories, but there are alternatives like Bitbucket and Gitlab

Over time, releasing projects publicly on GitHub serves to build up a portfolio, which is one good reason to make as much work public as possible.

  1. Signup for github

  2. Create a repo called website

  3. Setup SSH/HTTPS

  4. Push a index.html file

    • With contents of

      • Name

      • College Name

      • Course name

<!DOCTYPE html>
<html>
  <head>
    <title>Hello, world!</title>
  </head>
  <body>
    <h1>hello, world</h1>
    <p>Call me <name></p>
    <p>I am studying <course> at <college></p>
  </body>
</html>
  • Create a branch called about-me

    • create about.html

<!DOCTYPE html>
<html>
  <head>
    <title>Hello, world!</title>
  </head>
  <body>
    <h1>About <name></h1>
    <p>Hobbies & Interests: <name>.</p>
  </body>
</html>
  • push branch to Github.

  • Submit PR

  • Merge PR

Github pages

git checkout -b gh-pages
git push -u origin gh-pages

browse to http://<username>.github.io/website

  • add link to about page in website

  • on the about page, add a link back

Version Control Practice

Set up Git

On Github

  • Add everyone at your table to your repo

  • Pick one repository from your table that you have not contributed to before

  • Create new file with branch

  • Create PR

Bonus

Create a PR in the index.html to link to your new file with a <a> tag.

Last updated