DEV Community

Christopher Njoroge
Christopher Njoroge

Posted on

Understanding the Git Workflow:Working directory,staging ,commit and push.

What is Git and Github

This is a version control system or tool used to track changes by developers.
When one installs git it comes with an inbuilt terminal called gitbash

Github is a cloud based platform for storing git repositories online.
Just sign up for free,verify via email and your account is created.
git and github are connected using a SSH KEY.

How Git works.

We start by installing git on my Pc, after installation check if git is installed by opening a terminal eg powershell on windows and run git --version

Stages

Git/Github is broken into four simple stages:

  • working directory is where we write code and amend and delete files. Here changes are made but cannot be tracked unless they are instructed to commit.
  • staging phase is an area where files are modified.
  • commit phase is where git takes everything from the staging area and sends it to our local repository.
  • push phase is where the saved commits are sent to a remote repository like GitHub.

Creating folders and files on git bash

  • First identify where we want the folder to be located ls is used to list mkdir "name of the folder" (means make directory) cd " name of the folder"(change directory)

Readme texts README.md end with .md since they are written using markdown language.Can use echo,touch or nano commands to write a readme file.
If i want to know the contents of my readme file we use:cat README.md

  • git config-this is basically telling it my identity
    git config --user.name"user"
    git config --user.email "useremail"

  • git init-this command is used to create or initialize a repository in main/master.
    git init main

  • git status-shows the repository status. This command shows changes and what is happening in git
    git status

  • git add-stages changes made
    git add .this means stage all or one can specify what to be added e.g i want to add only a javascript folder git add script.js

  • git commit-commits records that have been staged in the local git repository.Its like getting a snapshot or memory of the file.
    git commit -m "commit message"

  • git log-shows a history of all the commits that were made.
    git log

git branch should return main

To upload my git folder on github:

Open the github account,create a new repository,click on ssh and copy the link
git remote add origin "paste the ssh key link"

git remote -v

  • git push-this command to send commits to the remote repository git push -u origin main. Git will send the files to my github repository,i can refresh my github and see them.

What is a SSH KEY?

SSH stands for secure shell which is a protocol that allows a computer to communicate with another computer over a network.

Generating an SSH key?
ssh-keygen -t ed25519 -C "email signed on github.com"and press enter, the passphase(password authentication)is optional.
This command will generate two keys:example
ed25518
ed25518.pub
The one with .pub is the public key which is the one that we share with github while the other one is a private key which should not be shared.

Adding the SSH Key to Github-open my github account,on settings click on SSH and GPG keys, create a new key and copy the public key that we generated.
Testing the SSH connection
Test before pushing a project using ssh -T git@github.com

Top comments (0)