Skip to content

2. Project management

This week we learned all about Git, which is an open-source distributed version control platform. I have some experience with version control, but it has been a while and I excited to finally have a solid reason for learning and taking it seriously. The following page will layout my workflow in learning and setting it up.

Git | Official Documentation

Fab Academy Git Tutorial

Fab Academy Git Recitation Slides

Dangit, Git!?!. A website with common Git issues and solutions.

Git Tower. A Git tutorial.

What is version control | Atlassian Git Tutorial. Another Git tutorial.

Getting Started

I have decided to make my life a little more difficult and have two setups for the year. I have a desktop PC running Windows 10 at the Haystack Office Lab, which I work from 2-3 days per week. I also have a home lab that I am slowly setting up for Fab Academy and will be using a laptop running macOS. This might give me a good feel for both platforms and ultimately help me decided which platform works best for us here at Haystack.

There are a couple of cloud-based services/servers that utilize Git. This includes Git Lab, Git Hub, and Git Book, among many others as well. For the purposes of this course, I would like to focus on learning and understanding the following:

  • Using Git from the command line (terminal).
  • Using a Git Repo to host and manage a project, such as a website, book, or construction project.
  • Understanding the differences between GitLab, GitHub, and GitBook and when to use which tool for particular applications.

The whole essence of Git is about version control. So, in theory, you can apply this logic to just about anything that requires iteration. Hence, books, websites, and design projects. I would also like to approach this with a CLI (command-line interface) for most things, unless absolutely necessary. So, step one is to install package manager for the mac.

Installing Homebrew on macOS (via Terminal)

Homebrew is a popular package manager for macOS. I was able to install

I ran into permission issues when trying to use the above code. You need to make sure that you are indeed the administrator on the computer AND that you have a password set. I had a blank password/no password set for my account and Terminal was not happy about this. Once I setup an account on my macOS device with a password, then I could enter a root password and install home brew.

Installing Git on macOS (via Homebrew)

$ brew install git

Once you have installed homebrew, installing git is done easily through the above command. It takes about 5 minutes to install on my computer at my home because I have embarrassingly slow internet service. Again, I live on an island in rural Maine.

Git Essential Training

What is distributed version control? The opposite of a central version repository. Different users maintain their own repos. No central repo. Changes are stored as change sets. Tracks changes, not versions. Change sets. Merge in change sets, or apply patches between the different repos. There are many working copies. No dedicated master REPO. Convention is to set one primary REPO.

  • Faster, not network access required, no single failure point.
  • Encourages participation and forking of projects, collaboration.
  • People can work independently, submit change sets for inclusion or rejection.

Configuration

Global

which git
git --version
git config --global user.name "James Rutter"
git config --global user.email "fablab@haystack-mtn.org"
git config --list
cat ~/.gitconfig
git config --global core.editor "atom --wait"
git config --global color.ui true

The above commands were used in the last chapter to set global configurations for the Git instance on my Macbook laptop. Most important is the feature which sets the default editor. There are User and Project level configurations but I haven’t learned anything about those yet.

User

I didn’t set any user specific config settings. I don’t think I need to since I am the only user on my computers.

Project

Again, I didn’t set anything here. Maybe I will need to eventually for my Fab Academy repo project. More on that later.

Auto-Completion

Git-Completion Bash Utility

The above link will take you to the source code for a script that will enable auto-complete within git. I couldn’t get this to work, so I am going to move on. Maybe at some point I can get this working and use Autocomplete.

Initialize a Repository

The following section describes my practice with Git, independent of the Fab Academy repo. I just wanted to learn about Git through the CLI without messing anything up.

git init

Navigating to the desired directory and typing the above command will initiate a git repository in the directory and place a “.git” file in that directory as well. That is about all I know so far. This is actually a directory, within it has all the git project repository files and config.

Changes, Workflow, and Committing

So, the workflow using git is as follows. First, you make changes to the project directory. This could be adding a new file, modifying a preexisting file, or deleting something. Changes. Then you ADD the changes, and then you COMMIT the changes, usually adding a message to note or describe the changes you are making.

git add .
git commit -m "Initial commit"

Commit Messages - Best Practices

  • Single one-line summary of the changes
  • Present tense
  • Clear and concise

Git Concepts & Architecture

Three Tree Architecture: Repository > Staging Index > Working

SHA-1 Values

Head Pointer

git status

Changes & Differences

git diff

Setting up Fab Academy Git Repository

SSH Keys

Setting this up for each device that will need access to master repository. Today, I am just going to get my Macbook Air setup for this. To create a public key on this device, run the following commands.

ssh-keygen
pbcopy < ~/.ssh/id_rsa.pub #copies the SSH SHA key to clipboard

Hit enter to save the default file and location. I did not use a password. Copy password and paste into GitLab SSH Key form. This all seemed to work okay.

Cloning Git Repository

Once SSH key is generated and linked to GitLab, then cloning is easy. I just created a director on my local computer “FabAcademy” and cloned the repo using the following command.

git clone git@gitlab.fabcloud.org:academany/fabacademy/2021/labs/charlotte/students/james-rutter.git

The following URL was copied directly off the CLONE button from GitLab. I created a new directory on my computer to work from (FabAcademy). Once cloned, git put a new working folder on my computer (james-rutter). This is my gitlab repo for Fab Academy.

Editing and Adding Files to Git Repository

I am using Atom with the james-rutter directory project loaded. This gives me quick access to all my Fab Academy student files for generating a website. Eventually, I will create my own custom website, but for now, let’s keep in simple. The below screen shows how to update the local Git repository, add changes, commit those changes, and then push to the online, fab cloud, repository.

git push #do this to update cloud repository
git pull #do this to pull most recent version from cloud repo, merge with local

Using Git through Atom

I just discovered today how to access Git through Atom and it is a game changer. I am glad I learend CLI methods first, because I have a better intuiton as to what is going on but it is so much faster to do everything within Atom.


Last update: February 3, 2021