GETTING STARTED WITH GIT…

JOSEPHINE CHIKA
7 min readMay 7, 2018

--

Still on the journey of everything is learnable @Genesystechhub

Today being 7th May, 2018, I walk through the process for using Git locally on my personal computer, and using GitHub to back it up. Before this day, I walk through creating my personal GitHub account, installing or setting up Git on my computer as instructed and directed by my instructor.

NOTE:

copied, but is true

What is Git? Git is a version control system which enables you to track changes to files. It is entirely file based itself, meaning there is no additioanl software or applications required except Git istelf. Using Git, you are able to revert files back to previous versions, restore deleted files, remove added files and even track down where a particular line of code was introduced. Git creates a .git folder (in the current folder) to store the details of the file system - this folder contains all the data required to track your files and is known as a repository, or repo. Well explained and illustrated by Nwangwu Ositadinma.

Getting Started with Git. How it all begun…

Following instructions; I created a folder in my document with name “Recipes” and added a file to it with name “peppersoup_recipe.txt” . I right clicked inside the folder and clicked on “Git Gash Here”. From the Git Bash environment I started with this git commands:

  1. git init — it Initialized empty Git repository
CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Recipes (master)$ git initInitialized empty Git repository in C:/Users/CHIKA JOSEPHINE/Documents/Recipes/.git/

2. git log Show list of all the commits, but because I have no commits yet it desplayed the output below.

CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Recipes (master)$ git logfatal: your current branch 'master' does not have any commits yet

3. git status — This will show a list of all the files affected during your working, plus show any files added or removed since your last commit.

CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Recipes (master)$ git statusOn branch masterNo commits yetUntracked files:(use "git add <file>..." to include in what will be committed)peppersoup_recipe.txt.txtnothing added to commit but untracked files present (use "git add" to track)

4. git commit — I wasn’t able to commit, because this is my first time, so the system required my info.

CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Recipes (master)$ git commit*** Please tell me who you are.Rungit config --global user.email "you@example.com"git config --global user.name "Your Name"to set your account's default identity.Omit --global to set the identity only in this repository.fatal: unable to auto-detect email address (got 'CHIKA JOSEPHINE@CJBEST.(none)')

Following the format in line 5 and 6 in the code above I have to configure my accounts by inputing my name and email address so as to enable the system recognize the user.

CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Recipes (master)$ git config --global user.email "josephinechika94@gmail.com"CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Recipes (master)$ git config --global user.name "Chika Josephine"

After configuring my details, I tried commiting again but first I used the command “git add -A”, followed with another code “git commit -m “initial commit”.

CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Recipes (master)$ git add -ACHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Recipes (master)$ git commit -m "initial commit"[master (root-commit) e5259fb] stages in preparing peppersoup1 file changed, 8 insertions(+)create mode 100644 peppersoup_recipe.txt.txtCHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Recipes (master)$ git logcommit 4d18f24fd6ecb6959ef718a27b3617ed364c38d6 (HEAD -> master)Author: Chika Josephine <josephinechika94@gmail.com>Date:   Mon May 7 13:58:44 2018 +0100initial commit

After my first commit I run the git log command again which showed me a list of all the commits (commit number) represented by SHA–1 followed by author, date and then commit message.

I added another commit, updated my file and also run a git log command

CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Recipes (master)$ git add -ACHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Recipes (master)$ git commit -m "stages in preparing peppersoup"[master (root-commit) e5259fb] stages in preparing peppersoup1 file changed, 8 insertions(+)create mode 100644 peppersoup_recipe.txt.txtCHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Recipes (master)$ git logcommit e5259fb2b0d2f3909555b79c555b1eb8dfcc6c4b (HEAD -> master)Author: Chika Josephine <josephinechika94@gmail.com>Date:   Mon May 7 13:58:44 2018 +0100stages in preparing peppersoup

I used the “git diff” to get the difference between the the first commit and the second commit.

CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Recipes (master)$ git diff e5259fb2b0d2f3909555b79c555b1eb8dfcc6c4b 4d18f24fd6ecb6959ef718a27b3617ed364c38d6diff --git a/peppersoup_recipe.txt.txt b/peppersoup_recipe.txt.txtindex 2c44a79..a9adb85 100644--- a/peppersoup_recipe.txt.txt+++ b/peppersoup_recipe.txt.txt@@ -6,3 +6,4 @@ ingredients- maggi- utazi- uziza+you must get it, just try and see

I added another commit by changing the word in my file “utazi” to “banana” and also run a git log command. Finally I have to run my “git status” command again, the it displayed “nothing to commit again, working tree clean”.

CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Recipes (master)$ git add -ACHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Recipes (master)$ git commit -m "changed utazi to banana"[master d34b157] changed utazi to banana1 file changed, 2 insertions(+), 1 deletion(-)CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Recipes (master)$ git logcommit d34b1578a456f373db6705c79abc367f5978ab19 (HEAD -> master)Author: Chika Josephine <josephinechika94@gmail.com>Date:   Mon May 7 14:09:41 2018 +0100changed utazi to bananacommit e5259fb2b0d2f3909555b79c555b1eb8dfcc6c4bAuthor: Chika Josephine <josephinechika94@gmail.com>Date:   Mon May 7 13:58:44 2018 +0100stages in preparing peppersoupcommit 4d18f24fd6ecb6959ef718a27b3617ed364c38d6 (HEAD -> master)Author: Chika Josephine <josephinechika94@gmail.com>Date:   Mon May 7 13:58:44 2018 +0100initial commitCHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Recipes (master)$ git diff e5259fb2b0d2f3909555b79c555b1eb8dfcc6c4b d34b1578a456f373db6705c79abc367f5978ab19diff --git a/peppersoup_recipe.txt.txt b/peppersoup_recipe.txt.txtindex 2c44a79..465c251 100644--- a/peppersoup_recipe.txt.txt+++ b/peppersoup_recipe.txt.txt@@ -4,5 +4,6 @@ ingredients- water- onion- maggi-- utazi+- banana- uziza+you must get it, just try and seeCHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Recipes (master)$ git statusOn branch masternothing to commit, working tree clean

Creating Repository and Cloning from GitHub Account

The journey didn’t end there, finally we have to create a repository on GitHub. Remember I said earlier that Git is different from GitHub.

From my GitHub account (which I have created already), I clicked on new repository button on the home page to create a new repository.

On the new repository page, I named my repository git_practice. After naming the repository, clicked on Create repository.

creating a new repo from GitHub

Clicking on create repository will navigate you to another page where you will be able to copy the clone link and clone it in a git bash environment.

I never knew that Git is a tricky subject to get your head around, till I get to the state of how to clone. Knowing the commands is one thing, but knowing how to use them is another.

CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Gitclass (master)
$ git add .
warning: adding embedded git repository: Documents/Gitclass/git_class
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint: git submodule add <url> Documents/Gitclass/git_class
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint: git rm --cached Documents/Gitclass/git_class
hint:
hint: See "git help submodule" for more information.

CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Gitclass (master)
$ git log
fatal: your current branch 'master' does not have any commits yet

CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Gitclass (master)
$ git commit -m "have to clone the file here"
[master (root-commit) d8accd0] have to clone the file here
2 files changed, 1 insertion(+)
create mode 160000 Documents/Gitclass/git_class
create mode 100644 Documents/Gitclass/gitclass.txt

CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Gitclass (master)
$ git log
commit d8accd0e33431bd4b14014494dfdbbea0d4653eb (HEAD -> master)
Author: Chika Josephine <josephinechika94@gmail.com>
Date: Mon May 7 15:20:25 2018 +0100

have to clone the file here

CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Gitclass (master)
$ git remote

CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Gitclass (master)
$ git remote

CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Gitclass (master)
$ git log
commit d8accd0e33431bd4b14014494dfdbbea0d4653eb (HEAD -> master)
Author: Chika Josephine <josephinechika94@gmail.com>
Date: Mon May 7 15:20:25 2018 +0100

have to clone the file here

CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Gitclass (master)
$ git push origin master
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I have to go through all this stress and outputing this long error code because I don’t know I have to activate the directory with the command “cd” before adding a commit.

CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Gitclass (master)
$ cd git_practice

CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Gitclass/git_practice (master)
$ git add -A

CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Gitclass/git_practice (master)
$ git commit -m "I added an empty file inside my repo"
[master d32ac72] I added an empty file inside my repo
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 gitclass.txt

CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Gitclass/git_practice (master)
$ git log
commit d32ac72c2b9d18171eb10ff5861bc89b9481d3b0 (HEAD -> master)
Author: Chika Josephine <josephinechika94@gmail.com>
Date: Mon May 7 15:41:39 2018 +0100

I added an empty file inside my repo

commit 4d18f24fd6ecb6959ef718a27b3617ed364c38d6 (origin/master, origin/HEAD)
Author: Chika Josephine <36519252+josychika94@users.noreply.github.com>
Date: Mon May 7 15:11:47 2018 +0100

Initial commit

CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Gitclass/git_practice (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)

nothing to commit, working tree clean

CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Gitclass/git_practice (master)
$ git remote
origin

CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Gitclass/git_practice(master)
$ git push origin master
fatal: unable to access 'https://github.com/josychika94/git_practice.git/': Could not resolve host: github.com
DONT PANIC BECAUSE OF THE LAST STATEMENT, THERE WAS NO INTERNET CONNECTION THAT WAS WHY IT COULD NOT RESOLVE HOST.
CHIKA JOSEPHINE@CJBEST MINGW32 ~/Documents/Gitclass/git_class (master)
$ git --version
git version 2.15.0.windows.1

Thank God, finally, I traced the right path lo and behold there I have it! I pushed it online with the command “git push origin master” (origin and master are paths).

“My first GitHub repository, linked to your local Git repository.”

--

--