DEV Community

Isaac Mageto
Isaac Mageto

Posted on

GIT AND GIT BASH

GIT AND GIT BASH

See my first week at LUXDEV ACADEMY has been nothing short of extraordinary.

From the orientation bit – to the installation of key softwares and explanations of their workings has been just incredible.

Now am into week 2 and have gotten to learn more about GIT and GIT BASH.

Now for me I will try to break it down into a way that applies logics for simplification and understanding – so lets get into it.

1. GIT

Now Git is a software in our local computers that gets to do a bit of everything and channels communications to other key softwares in our case Git Bash (which we shall look into later) and how they get to “talk” and get your local machine upload and get you work to the public.

So first lets get through some commands and what they get to do in Git Bash.

A – THE NAVIGATION

pwd

This command gets you to know where you are at the current moment ie folder.

So the logic is if you run pwd you are telling Git Bash “where am standing at currently so that we can continue navigating through your work you need to know where you are.

$ pwd
/c/Users/isaac.mokua/OneDrive/desktop/Kenya-hospital-records-analysis
Enter fullscreen mode Exit fullscreen mode

ls

If you run this command you are basically telling Git Bash “what are the current lists am working in/with within my folder or repo

then Git Bash will basically list for you the files and folders that are available.

$ ls
data/  README.md
Enter fullscreen mode Exit fullscreen mode

mkdir

When you want to create a new structured folder in my case for my school work I will run the “mkdir “ command – to basically tell Git “ we are creating a new working folder in our local machine that we will be working with for our assignments and class work.

For example “MKDIR DATA “ we are creating a new folder named – data that we will be working on/with.

Note: mkdir is a "quiet" command; it doesn't "speak" unless there is an error!

$ mkdir data
$
Enter fullscreen mode Exit fullscreen mode

cd

Change directory (CD).

Remember when we had created a new folder named data – so running the “Cd “ command we are telling Git – we need to move into the folder named data _ more like opening the doors to the folder named data in our local machine and get to interact with the folder.

$ cd data
isaac.mokua@CK-MOQICT-L002 MINGW64 ~/Project/data
$
Enter fullscreen mode Exit fullscreen mode

2. Writing contents and reading contents

So since we are inside our folder named data we need to write the contents of the folder – basically readable contents.

So we run:

readme.md

This file is what we get to outline the workings of the file inside the data folder.

We will be outlining what we are doing within our data project as a whole to the public so that they get to better understand what we are doing.

Once ran, you will notice our readme file does not have any contents so we need to write contents.

To do this we run:

$ touch README.md
$
Enter fullscreen mode Exit fullscreen mode

Echo “-“ – command

This basically will tell Git “i want to be able to write my contents in my readme file, but one important thing to note, is inorder to structure our readme file well into a well readable file we need to use the “#” command.

  1. Echo “#---“ – this will basically create the header for our readme file
  2. Echo “## -- “ – this command we shall be creating a subheader in our read me file.
$ echo "# Kenyan Hospital Records Analysis" > README.md
$
Enter fullscreen mode Exit fullscreen mode

So finally once we do that and have added the contents we want the public to read as they get to interact with our works we can get to read the contents directly from terminal we use the:

Cat readme.md

This command when ran – Git will basically outline for you all the written contents within your readme.md file.

$ cat README.md
# Kenyan Hospital Records Analysis
Enter fullscreen mode Exit fullscreen mode

Now another command in Git that helps you write contents within our readme.md file is the:

Nano readme.md

This command will open an editable panel withn Git that you will then write your contents thus the header subheaders and subsequent contents that will lie within our readme file.

So after you are done – to save use the “CTRL+O+ Enter “ to save our file, then after we are done inorder to go back to terminal use the “CTRL+X” to go back to our Git terminal.

$ nano README.md
(The screen clears and opens a text editor inside your terminal)
Enter fullscreen mode Exit fullscreen mode

3. Moving our works to Git Bash

Then after we are done with this process its time for us to move our works to Git Bash – our main hub where all files and works we have done that we want the public to access in our repositories sit.

In our case we want to move contents within our data folder to GitHub.

SSH Keys

SSH – (secure shell keys) basically is a key used to connect your local PC to Git Bash – so to always avoid typing or keying in your password every now and then from terminal when working – Git offers a simple solution of a secure shell key that then becomes the safe personalised key between Git and Git Bash, so everytime you are working on anything in Git, it becomes easier to push it to your repository since Git and Git Bash have a “common key “ that is safer faster and more secure and that is able to make the 2 programs communicate and exchange “ information “ easily avoiding tiresome forms of work to a user.

$ ssh-keygen -t ed25519 -C "********@*****.com"
Generating public/private ed25519 key pair.
Enter file in which to save the key (/c/Users/isaac.mokua/.ssh/id_ed25519): 
Your identification has been saved in /c/Users/isaac.mokua/.ssh/id_ed25519
Your public key has been saved in /c/Users/isaac.mokua/.ssh/id_ed25519.pub
Enter fullscreen mode Exit fullscreen mode

4. Git tracking our works

First we need Git to take charge of the works inside our Git terminal ( the ones we have had the readme file and data file” – the logic here is Git is able to track and take charge of our files, incase of anything we are able to edit or do any other checks etc to our file, as well as Git will get to know the distinctive features and works inside our data.

Remember all works are unique so Git will be able to even “know about each and offers flexibility, so we can work an other stuff as well without loosing track or works we were doing. Running this command Git automatically add the “.git” that will basically record any changes that user makes going forward.

$ git init
Initialized empty Git repository in /c/Users/isaac.mokua/Project/.git/
Enter fullscreen mode Exit fullscreen mode

Git status

This command is to basically run the status or basically “where are we currently “ within our folder and the works we are conducting.

$ git status
On branch main
Untracked files:
  (use "git add <file>..." to include in what will be committed)
    README.md
    data/
Enter fullscreen mode Exit fullscreen mode

Git add .

This command basically is like pushing our data folder in line – to be “ready “ to go public within Git Bash but most important thing yet to know it has not been moved its just static ready to “launch “.

$ git add .
$
Enter fullscreen mode Exit fullscreen mode

5. Connecting to the repository

git remote add origin (paste your ssh git bash key)
Enter fullscreen mode Exit fullscreen mode

Remember the logic of Git offering flexibility when working and making changes to your folder/data or works, this command in Git offers that – so basically the logic is you are telling Git “always make changes to this repository that am pointing you to “ since all changes and works are unique and to avoid any mixup when needing to changes on particulars of your pushed code/works to Git Bash – so Git knows what specifically to check and target/make changes to.

$ git remote add origin git@github.com:MOKUA122/Kenya-hospital-records-analysis.git
$
Enter fullscreen mode Exit fullscreen mode

6. Launching our works

The Commit (Taking the Snapshot)

$ git commit -m "Initial commit: Added data and README"
[main (root-commit) 7a2b3c4] Initial commit: Added data and README
 2 files changed, 15 insertions(+)
 create mode 100644 README.md
 create mode 100644 data/Kenyan_Hospital_Health_Records.xlsx
Enter fullscreen mode Exit fullscreen mode

The Push (The Launch)

$ git push -u origin main
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Writing objects: 100% (5/5), 450 bytes | 450.00 KiB/s, done.
Total 5 (delta 0), reused 0, pack-reused 0
To github.com:MOKUA122/Kenya-hospital-records-analysis.git
 * [new branch]      main -> main
branch 'main' set up to track 'origin/main'.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)