Introduction To GitHub (Raspberry Pi)

Today I am looking at some commands to quickly get up and running on GitHub using a Raspberry Pi. The same instructions should work within other Linux based terminals and Mac OS X (minus apt-get).

Wikipedia says that Git is:

“…a distributed version-control system for tracking changes in source code during software development.It is designed for coordinating work among programmers, but it can be used to track changes in any set of files.”

Installing Git

Git can be installed via sudo apt-get install git

sudo apt-get install git
sudo apt-get install git

Checking Git Version

The version of Git can be checked via git –version

git --version
git –version

Adding Attributes To Local Git Account

After installing Git, or checking that Git is installed, it is time to add some attributes to the local Git account. If you are the only user of the Pi then the following can be used:

To add a username:

git config –global user.name “USERNAME”

geektechstuff_git_username
Git user.name

To add an email address:

git config –global user.email “EMAIL_ADDRESS”

geektechstuff_git_email
git user.email

With the local Git set up, it is time to use GitHub.

GitHub Account

A GitHub account can be created at https://github.com/, once created you can store code repositories online and branch off from other user’s repositories. Looking for some repositories to clone or branch from? Then try the GeekTechStuff ones at https://github.com/geektechdude?tab=repositories

Clone Repository

Once you have found a repository you want to use you need to clone it locally.

Within a repository click the “Clone or download” button (the green button in the below screen grab) and copy the HTTPS URL.

GitHub Clone With HTTPS
GitHub Clone With HTTPS

Within a terminal type:

git clone URL_FROM_GITHUB

e.g.

git clone https://github.com/geektechdude/Python_PDF_Merge_Flask_Site.git

git clone
git clone

The git clone command will copy the repository from GitHub to your Pi, this includes all of the files within the repository. To view the files use the terminal to navigate to the folder (named the same as the repository), e.g.

cd REPOSITORY_NAME

for me this is:

cd Python_PDF_Merge_Flask_Site

GitHub Repository & Local Repository
GitHub Repository & Local Repository

Editing Files

The files in the local repository can now be edited or more files added using your favourite editor. As an example,

nano README.md

to open the nano editor and start editing the README.md file.

Status Check

If you want to see what files have been modified / changed then it is time for a status check:

git status

can help. Continuing with the example of editing the README.md from above, running the git status command will show that README.md has been changed.

Git Status
Git Status

Adding Files / Committing Files

Once a file has been modified / added then we need to add it to the snapshot of working files that we have using the git add command:

git add FILENAME

To add multiple files e.g. multiple Python (.py) files, a wildcard can be used:

git add *.py

A commit is then needed, which is a way to say we want to commit some changes. When doing this it is best to add a comment/message using the -m option.

The command looks like this:

git commit -m “COMMENT”

Time To Sync

With the files edited / added it is time to push them from the local repository back to the GitHub repository, this is done via:

git push origin master

GitHub will ask for your GitHub username and password during this stage. If you have 2 factor authentication turned on you will need to generate a Personal Access Token and enter that instead of your GitHub password.

geektechstuff_git_push_origin_master
git push origin in action

If the push is a success then the update will also show on the repository’s page on GitHub.

 

2 responses to “Introduction To GitHub (Raspberry Pi)”

  1. Git Ignore & Git Log – Geek Tech Stuff Avatar

    […] tackled some of the basics of Git / Git Hub in my previous blog post. Today I am going to look at Ignoring and […]

    Like

  2. Creating A Repository in AWS Git, a.k.a. CodeCommit (AWS) – Geek Tech Stuff Avatar

    […] has its own Git repository system called CodeCommit. Here is what AWS have to say about […]

    Like

Welcome to GeekTechStuff

my home away from home and where I will be sharing my adventures in the world of technology and all things geek.

The technology subjects have varied over the years from Python code to handle ciphers and Pig Latin, to IoT sensors in Azure and Python handling Bluetooth, to Ansible and Terraform and material around DevOps.

Let’s connect