Remember that cart253 folder we cloned (downloaded) using GitHub Desktop? That is our repository for this course. To use version control, we will store all our work in this folder.
Let’s go through the process of starting a new project. You’ll do this a bunch, both for tiny little test projects for a single class module and for giant works of genius for class projects and for your own personal stuff. The process is always the same and you should always follow it:
As you improve your programming you will probably start projects in many different ways, but for now you will always use a template that will give you all the files you need:
You should have a folder called template-p5-project which contains a bunch of files you will use to make JavaScript projects. We’ll talk about the details later on.
template-p5-project is not a good name, though, so:
version-control-workflowYou should always give your project folder a relevant name.
Because this is a project you’re working on for CART253 specifically, you need to move it into the CART253 repository. And you should get into the habit of organizing that folder:
cart253 create a folder called topicstopics create a folder called version-controlversion-control-workflow folder into the version-control folderThe topics folder will allow you to create subfolders to store your work when you’re following along with the modules of this course.
Because starting a new project by copying a new template folder into our repository is an important change, this is the first moment we’ll use version control.
The process is pretty mechanical, so the main thing is just to learn the steps and you can worry about the details as you get more confident.
You should see that GitHub Desktop has opened your cart253 repository (top left) of its window.
Because there are now changes to the repository folder (the new project was added), GitHub Desktop will list the changes made in the Changes tab. This will look like a list of a bunch of files that were added in this case.
To commit (save) your changes to the repository you first write a commit message that is a short, clear description of what has changed, and then you commit (save) those changes:
Now the changes we made are saved in the repository’s history on your computer.
(You can go to the History tab to see your commit there, complete with the description you wrote.)
Remember: Writing a clear description of the changes you made it very important when using version control.
To make sure your repository is the same on your computer and on github.com, you need to push the new commit:
You’ll see a little bit of action as your changes are uploaded to github.com. When that’s done you’re all in sync with your repository on github.com. That’s good because if your computer suddenly disintegrates or jumps out the window, all your work will still be on github.com (just like with DropBox or Google Drive, etc.)
Hot tip: It’s almost always a good idea to commit and push at the same time so that you remember to do both.
We’re now going to pretend to work on the project so that we can get a taste of how we’ll use version control most of the time. The process is pretty similar to what we’ve seen:
We’re ready to start work on the project itself. We’re programming so we will open the project folder in VS Code. It’s important that you open the project folder in VS Code rather than one of the files in it.
File > Open and select the folderFile > Open Folder... and select the folderHowever you do it, you should end up seeing something like this:
You quite possibly don’t know how to program yet, so it would be unfair to ask you to write a program. Instead, open the script.js file inside the js/ folder in your project (use the left-hand pane) and replace the text inside that file with the workflow example code.
It’s important to constantly check your work in the browser because that’s the place your code actually runs:
(If the browser it opens isn’t Google Chrome, either changes your default browser to Google Chrome or copy the URL from the browser and paste it into Google Chrome.)
You should see the program has drawn a top-down view of a yellow pyramid and a red circle. You should be able to move the red circle with your mouse.
Because this is a significant block of work we need to commit it to our repository to save our progress:
script.js has changes)And now your repository is all up to date again, with another chapter in the beautiful history of your work.
Note: you don’t need to commit every tiny change we make but just “significant” blocks. As a rule it’s better to commit too often than too rarely though. The instinct for this will come with time.
You go on like this forever. You make some more changes to the project, then you commit and push. Then you make some more changes, you commit and push. And so on.
For practice:
background(0, 0, 0) function?const levels = 10 to another number?createCanvas(640, 640)?(320, 320, level * 48, level * 48)script.js file)And feel free to keep going with a new set of changes if you want to, making sure to write a new message and then commit and push.
That, my friend, is the version control workflow. Learn to love it. It’s basically just about saving your work along with a description of your work.
Whenever we start a new project you:
Whenever we work on your project you: