DEV Community

Velma Ketra Lukaya
Velma Ketra Lukaya

Posted on

The Git-Github workflow- A simplified cheat sheet

Introduction

Git and Github are tools that work together in managing and storage of your projects
Git is a version control system that runs on your computer and keeps track of changes made to you file and folder locally, while GitHub is an online platform where the Git repositories can be stored and shared as backup and to collaborate with other people
For the purpose of understanding, I created a project called Kenyan hospital health records on my local computer

General workflow

The overall process is
-Connecting your computer to GitHub using the SSH

  • Configuring your user name and email
  • Testing the connection

-Using Git to move my project from my Local computer to GitHub

  • Initialising Git
  • Staging the files
  • Committing staged files
  • Creating a Github Repository
  • Connecting the local repository to GitHub
  • Pushing the project to GitHub
  • Pulling changes from GitHub to local computer

Part 1: Connecting Git to GitHub using SSH

Before creating a new SSH, check whether your computer has one by opening the terminal and running:
ls -al ~/.ssh

If you do not already have it create one using ssh-keygen -t ed25519 -C "your_email@example.com"
which would create a public and private key to be kept private and in secret

Display and copy the public key to be added to GitHub settings and add a new SSH key, give the key a name e.g My computer, paste your key and click add SSH key

Check your Git configuration by using git config --global --list and test whether your computer communicates with GitHub by running ssh -T git@github.com

This confirmed that my computer was successfully connected to GitHub through SSH.
Now you are ready to push your local project onto GitHub

Part 2: Creating folders and files on your local computer

Using terminal, run pwd to identify the exact location
Thereafter, use the command cd to move into the desired location eg cd Desktop to move in to the desktop. You can use the same command to move into a directory of choice eg Documents
Within the desktop, use mkdir which instructs the terminal to make a directory inside your desktop
Cd into that folder and create folders of choice using mkdir and files of choice using touch e.g. touch README.md

To confirm, use ls to list out all components of your folder.

If you have any changes to make onto your README.md file , use
echo "# Your description in makrdown langage" > README.md
If you use **>
it overwrites everything un the README.md file while >> adds additional information into the README.md as such echo "Additional information" >> README.md without erasing existing information
Alternatively nano README.md and make all changes using markdown language, save and revert to terminal.
To confirm changes made, use cat README.md

Part 3: Initialise GIT

Initialise the git repository

Run git init. This instructs Git to start tracking your project and creates a hidden .git folder inside your project

Check Git status

Run git status which is important to inform you about hat is happening inside your repository
At this stage, Git will show you that there are files that are not being tracked yet

Stage the files

Run git add . to add all files to the staging area and if you check status you will see that git has begun tracking your files
as such

Committing the files

Using the command **git commit -m "describe the commit"

Part 4: Create the GitHub repository

In your GitHub account, create a new GitHub repository and name it similarly to the local project
This creates an online repository
At this point you now have a local repository and an online one but they are still not conected
On your GitHub repository you will have a SSH/HTTPS repository URL which you will use to tell your local repository where your GitHub repository is located
copy the key and on terminal add
git remote add origin *SSH repository URL*

Check that the connection had been saved using git remote -v
where you will see such results

Set the branch of your project to main by using git branch -M main
Confirm the branch of your project is set to main by using the command git branch

Once at this stage, you are ready to push the committed projects onto git hub

On the terminal, use git push -u origin main
The command means:

  • git push → send my commits to a remote repository
  • origin → the GitHub repository I connected earlier
  • main → the branch I want to send
  • -u → remember this connection for future pushes

On Github confirm that the project is now successfully uploaded

Henceforth

  • Check any changes you have made using git status*
  • Stage the changes using git add .
  • Commit the changes using git commit -m "Describe your changes"
  • Push the changes to GitHub using git push -u origin main"

If you make changes on git hub
you can simply git pull and the changes made in your online repository will be synchronized to you local repository. This fetches the changes and integrates them into your current branch

In a nutshell

Git runs on my computer and tracks the history of my project.
GitHub stores my Git repository online.
SSH provides the secure way for my computer to authenticate with GitHub.

Top comments (0)