Using Github for Windows

This document briefly explains using Github within the Windows OS - in this case Windows 7

Github for Windows was downloaded from https://git-scm.com/download/win

After downloading and running the executable Git BASH,Git GUI and Git CMD are installed. This tutorial will mainly deal with Git BASH to configure and operate Git.

GIT is a distributed version control system where a user or users files are stored on a remote server (GitHub) and one or more local computers. The remote servers and the local computers each host a GIT repository with the idea that these repositories are regularly synched together creating an up to date store of all users files, along with version information and changes.

For Fab Academy 2017 each of the participating FabLabs hosts a Git repository on GitHub. Students of a participating Fab Lab are required to first of all clone their Lab's GitHub repository onto their local computer. Then any files the student creates or changes are pushed back to the GitHub repository maintaining an accurate and current store of all that student's work and any of their colleagues. To ensure remote and local repositories are up to date it is required that students regularly pull (download) and push (upload) to the remote repository.

The steps outlined below indicate what is required to first of all clone the Fab Lab remote repsository and then to pull and push content between remote and local repository

  1. Configure Git with user ID and email
  2. Generate SSH key
  3. Clone remote Fab Lab repository
  4. Pull content from remote repository
  5. Push new content from local repository to remote Fab Lab repository

1 Configure Git with user ID and email

Run Git BASH and at the command prompt type in your user name and email

For more information see https://help.github.com/articles/setting-your-username-in-git/

2 Generate SSH key

The SSH key allows the local computer to securely access the remote repository

This key can be generated using Git BASH. Run Git BASH and at the terminal prompt type

ssh-keygen

The screen shot below shows an example of what you should see in the terminal window. Note while Git BASH prompts for a user file don't enter a name, just press return. Do the same when prompted for a password, don't enter anything just press return

This should generate an .ssh folder in your computer's local user directory and save two SSH files to it . See example below.

On my Windows 7 machine I orignally had problems with this as there was no .ssh folder created and consequently no SSH files stored in it. I had to manually create a folder called .ssh in the user root directory. This may only have been a problem with my machine but it is mentioned in case someone else has the same problem. Once I created the folder Git BASH successfukly saved the ssh files to it.

Once the key has been generated it is necessary to go to your user profile on the Fab Lab GitHub and copy the text from the file id_rsa.pub into the ssh key text box on your user profile. Once this has happened you have access to your Fab Labs repository and can begin cloning this to your local computer

3 Clone remote repository

Using Windows Explorer I created a folder in my C drive. This was called gitfabacadmeny. I have had problems with names containing upper case so recommend all folders and files be lower case.

Run Git BASH an at the terminal prompt change the working directory to the folder where the repository is to be stored:

cd: c:/gitfabacademy

Again in Git BASH clone the repository to this working folder by entering the terminal commands. Note the URL of your Lab's remote repository will be unique

git clone git@git.fabacademy.org:fabacademy2017/fablabname.git

For the Nerve Centre Fab Lab the URLis git@git.fabacademy.org:fabacademy2017/fablabnervecentre.git

Once the repository has been cloned you can view the repository directory structure to see if the clone has been successful

4 Pull content from the remote repository to the local repository

Before uploading content to the remote repository it is a good idea to download or pull the most up to date version of the files/folders on the remote repository to the local machine's repository. Within the Fab Lab Academy Github repository the student will have been allocated a folder. It is within this folder that you add or change any files or folders. With GitBASH runing and making sure the working directory is set to where the files/folders are to be download type the command

git pull origin master

5 Push new content from local repository to remote Fab Lab repository

Pushing content to the remote repository uploads the files and folders on the local computer's repository to a central server. Others can then connect to this server to view or modify the uploadded content.

Before doing this any new or changed files need to be added to the GitHub repository's database. Withoin GitBASH the user can types in the command

git add "filename"This adds an individual file to the database

or

git add -AThis adds all files that have been changed or added to the database

Once the files have been added the next step is to commit the files to the repository with the command

git commit -m"your message"The -m parameter adds a message to the commit command.

Once the files have been committed the local repository can be pushed to the remote repository with the command

git push origin master