Difference between revisions of "Source Control"

From Coder Merlin
Line 31: Line 31:
{{ConsoleLine|Initialized empty Git repository in /home/jane-williams/Experiences/W1006/.git/|}}
{{ConsoleLine|Initialized empty Git repository in /home/jane-williams/Experiences/W1006/.git/|}}


Note that this repository exists locally, alongside your other files for the project.  ''There is no central server repository.''


{{Hint|
{{Hint|

Revision as of 21:11, 9 July 2019

Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
Undo-redo

Prerequisites[edit]

Background[edit]

Introduction[edit]

Source control enables us to track and manage changes to our code. This functionality becomes increasingly critical as the size of our projects grow both in terms of the lines of code and the number of coders. Source control shows us who changed the code and when. We're able to compare one revision of code to another. And, when necessary, we can rollback changes to a previous revision. Source control can be a tremendous help to you (and your team) when you want to easily recover from accidentally damaging a project and as such, provides you with the freedom to experiment without fear. However, you must use the source control system regularly and often or it won't be able to help you. In this experience we'll configure our source control system, learn (a bit) about how to use it, and then place our journals under source control.

Git[edit]

There are many options to choose from when selecting a source control system. We'll be using one called git, created by Linus Torvalds in 2005. It's a distributed version-control system, meaning that every Git directory on every computer is a repository with a complete history and full version-tracking abilities.

Configuration[edit]

As a first step, we'll need to let Git know about our name and email address. Be sure to change your name and email address appropriately. You'll need to be able to receive email at the address you specify in order to complete the setup process.

jane-williams@codermerlin:~$ git config --global user.email "jane@williams.org"

jane-williams@codermerlin:~$ git config --global user.name "Jane Williams"

Initialization[edit]

Let's setup a new directory for all of our experiences and within, a directory for this experience:

jane-williams@codermerlin:~$ mkdir Experiences

jane-williams@codermerlin:~$ cd Experiences

jane-williams@codermerlin:~/Experiences$ mkdir W1006

jane-williams@codermerlin:~/Experiences$ cd W1006

jane-williams@codermerlin:~/Experiences/W1006$ 

One can consider the structure of a project, consisting of directories, files, and the associated content, as two dimensional. The repository can then be considered a three-dimensional structure formed by storing every committed version of the project structure across time. In order to initialize the repository, we issue the init command in the root of our project:

jane-williams@codermerlin:~/Experiences/W1006$ git init

Initialized empty Git repository in /home/jane-williams/Experiences/W1006/.git/ 

Note that this repository exists locally, alongside your other files for the project. There is no central server repository.

Hint.pngHelpful Hint
Even though we're using git init on an empty directory, there's no requirement that we do so. It's perfectly fine to initialize git in a directory in which we've already begun work.

Key Concepts[edit]

Exercises[edit]

References[edit]