DEV Community

Ken Yegon
Ken Yegon

Posted on

I had a hard time understanding GIT, until I stopped viewing it as a concept to understand but a tool

Pushing repos to github from git was quite hard for me at first.I kept staring at the tutor do it with much ease,commands and expected outputs flawlessly.I was impressed and humbled in equal measure.It seemed like a very smart thing that maybe I wasn't cut out for.I thought maybe I could stick to my medical career. Then I understood one thing, GitHub and Git were just tools and not a concept in development.
By the end of this article, just like me you will have a good understanding of it. The catch though, is you have to relax your mind, don't overthink it , don't complicate it.
Before I understood it, I kept mulling over how experienced techies' github appeared and went back and forth from github checking the very complicated website;the repos branches , the green contibution graph, pull requests were a little too much for my eyes.The first problem I encountered was generating the SSH keys, which i am going to start with.
I didn't understand why Github needed SSH keys when it was password protected, or so i thought.Turns out SSH keys lets my computer and Github trust each other without requiring my password everytime I push(Time is of essence here).I opened Gitbash and ran:
ssh-keygen -t ed25519 -C "kenyegonkiprotich@gmail.com"
A few seconds it gave me this:

Your identification has been saved in /c/Users/User/.ssh/id_ed25519
Your public key has been saved in /c/Users/User/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:lJy+5vBdz6+QnyWBgrRu7JO4ET++e+QULDlz78q4XK0 kenyegonkiprotich@gmail.com

Along with a little ASCII art image apparently that's just a visual fingerprint, mostly decorative for a beginner like me.
This was the first moment it stopped feeling abstract. I had two actual files on my computer now, a private key and a public key.
To get the key , I ran:
cat /c/Users/User/.ssh/id_ed25519.pub
and copied the output into GitHub , under settings , SSH and GPG keys ,New SSH.
I then went back to Git Bash to test the connection by running:
ssh -T git@github.com
and got confirmation that i had succesfully authenticated.This was the first successes I had.

Now lets move on to the actual Git workflow.I made a practice folder and turned it into a Git repository.On Git Bash ,I ran:

mkdir git-practice
cd git-practice
git init

Git gave this output :

Initialized empty Git repository in C:/Users/User/git-practice/.git/

Then I created this simple file by running:

echo "This is my first Git practice file" > notes.txt

and checked status:

git status

which gave me the output:
Untracked files:
notes.txt

to show that the file was untracked.
This was the working directory.Git could see the file existed but it wasn't tracking it yet.Next I staged it:

git add notes.txt
git status

and the message changed to:

Changes to be committed:
new file: notes.txt

Finally I committed it:
git commit -m "add notes file"

output:

[main (root-commit) 4400b81] add notes file
1 file changed, 1 insertion(+)
create mode 100644 notes.txt

The last step was connecting my local repo to GitHub and pushing it up.I created an empty repository on GitHub , then linked it:

git remote add origin git@github.com:kenkiprotich/git-practice.git

and pushed:

git push -u origin main

Output:
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 249 bytes | 249.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:kenkiprotich/git-practice.git

  • [new branch] main -> main branch 'main' set up to track 'origin/main'.

On refreshing the GitHub page , there it was ,visible.

Looking back , I am cut out for this.

Top comments (0)