Skip to content

Version Control

Git

Git Guide

Git is a distributed version control (open-source).

Documentation

http://fabacademy.org/2019/docs/FabAcademy-Tutorials/week01_principles_practices_project_management/git_simple.html

Recitation (2021.02.01)

Dangit, Git!?!

What is version control | Atlassian Git Tutorial

Getting started with GIT on a mac. I have decided to commit to using macOS as a platform for Fab Academy. Haystack has made the switch to mostly macOS computers and while I know there will be some issues down the road with running machines, I think it will be a good experience as I have been working with PC/Windows for the past 5+ years. I need a challenge and change. I also use iPhone and iPad, so everything will sync, etc.

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) on a macOS platform.
  • 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.

GitHub

GitLab

GitBook

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.

Week%2001%20+02%2006ec8fc4ac35405687ba91ef04ac5de3/Untitled.png

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. Okay. Installed. Onto to GIT.

Installing Git on macOS (via Homebrew)

$ brew install git

Once you have installed homebrew, installing git is trivially done through the above command. It takes about 5 minutes to install. Now, what?

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

Project

Auto-Completion

https://github.com/git/git/blob/master/contrib/completion/git-completion.bash

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.

Initialize a Repository

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

SSH Keys & Remote Git Repositories

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. Then clone repo.

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.

Week%2001%20+02%2006ec8fc4ac35405687ba91ef04ac5de3/Untitled%201.png

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.

Week%2001%20+02%2006ec8fc4ac35405687ba91ef04ac5de3/Untitled%202.png

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

Recitation (2021.02.01)

Version Control and Project Management

Julian Gallimore, developer setup all the repos, setup accounts, etc.

Fab Cloud (GitLab)

  • self-hosted version of gitlab
  • Single Sign-On (SSO ) via Fablabs.io
  • Individual Project Page
  • Fab Academy Student Group Page
  • Notification update

Git

Clone your repo (need an SSH key)

Made edits as needed

bash git add (. for everything, file name for specific files) git commit -m "MESSAGE" git push du -sh * (get disk size, file size information) du -sh * | sort -n (sort files by size)

you only need to do “git add” to a file once, then git is tracking the file, no need to do this over and over again

git restore --staged README.md

git pull #fetch and merge of new commits into your local master branch
git fetch #ask server what the status of the online repo is
git pull --rebase #don't use this

GitLab CI

Continuous Integration (CI)

Continuous Deployment (CD)


Last update: May 7, 2021