Setting up git and github

Hello in this tutorial we are going to learn some basic git set up and commands

First of all set up a github account and then set up git in your local machine

Download git and github

Download Git from the official site here Create a github account here

To check whether Git is installed on your machine or not type the following command and see the output displayed with the git version

git --version

Configurations

Configure your Git and Github account type the following commands and make sure you enter the correct credentials

git config --global user.name "Your Name"
git config --global user.email "yourname@example.com"

Create your SSH key that will identify your machine hence you can upload to your repository without having to type in your username and password every time.

check if you have one by typing

ls ~/.ssh/id_rsa.pub

if you see this message “No such file or directory” you have to create one else proceed to the next steps

follow the steps below to create a SSH key


ssh-keygen -C <youremail>

Press enter to save it in a default directory

Go to your Github account –> Settings–>SSH&GPH Key–> NewSSH Give it a name which you can remeber easily then open go to the folder where you saved the SSH key and open the id_rsa.pub copy everything make sure it starts with ssh-rsa and ends with your email adress.

SSH

Now in the next sections we are going to

1 Create a git repository on github and copy it on your Computer

2 Commit changes

3 Check current repo status

4 History of previous commits

Create a Git repository on github and copy it on your computer

Go to your github account and create a new repository as shown in the image below

Click the button click the button Create a new repository and then enter the name of the repository as shown in the images below    

After creating the repository you’ll be redirected to a page as shown

Now create a directory and navigate it to where you want your project to be

Now in your repository in the github page navigate to the SSH option and copy the selected text

then in you local PC In the folder created type git clone followed by the created URL in my case i have

C:\Users\LENOVO\Desktop\test_git>git clone git@github.com:ian-yitzhak/testing_git.git
Cloning into 'testing_git'...

Now your repository is connected to your local machine type git remote -v to display the url created

C:\Users\LENOVO\Desktop\test_git\testing_git>git remote -v
origin  git@github.com:ian-yitzhak/testing_git.git (fetch)
origin  git@github.com:ian-yitzhak/testing_git.git (push)

Check current repository status In the command line , change the directory to the repository name directory in the folder where you made a clone to your repository

create a README.md type touch README.md

C:\Users\LENOVO\Desktop\test_git\testing_git>touch README.md

A new file called README.md will be created

to check the status of the repository type git status


C:\Users\LENOVO\Desktop\test_git\testing_git>git status
On branch main

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        README.md

nothing added to commit but untracked files present (use "git add" to track)

In our case above our file is not staged

Type git add README.md then followed by git status to see the output in the command line interface


C:\Users\LENOVO\Desktop\test_git\testing_git>git add README.md

C:\Users\LENOVO\Desktop\test_git\testing_git>git status
On branch main

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   README.md

your file is now in the statgging area

Commit your Repository Changes

To commit your change type git commit -m”create a README.md file”

C:\Users\LENOVO\Desktop\test_git\testing_git>git commit -m"create README.md file"
[main (root-commit) 6f964e8] create README.md file
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README.md

Checking history of the prevous commits

to check the history of the previous commits type git log to see the message coming out with the commit message

C:\Users\LENOVO\Desktop\test_git\testing_git>git log
commit 6f964e8489d55f27949cd18dfce250565ce01206 (HEAD -> main)
Author: ian-yitzhak <onyangoian71@gmail.com>
Date:   Mon Feb 1 22:40:31 2021 +0300

    create README.md file

Now lets repeat process 2 to 4 before we push our project to github

create a new file in the same directory then name it text.txt

C:\Users\LENOVO\Desktop\test_git\testing_git>touch text.txt

using your code editor open the project and then move to the RAEDME.md file and then add some text

in my case i have

Type git status to see the changes in the file


C:\Users\LENOVO\Desktop\test_git\testing_git>git status
On branch main
Your branch is based on 'origin/main', but the upstream is gone.
  (use "git branch --unset-upstream" to fixup)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        text.txt

no changes added to commit (use "git add" and/or "git commit -a")

Type git add . to add stage all the files

C:\Users\LENOVO\Desktop\test_git\testing_git>git add .

check whether the files have been staged by typing git status


C:\Users\LENOVO\Desktop\test_git\testing_git>git status
On branch main
Your branch is based on 'origin/main', but the upstream is gone.
  (use "git branch --unset-upstream" to fixup)

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   README.md
        new file:   text.txt

Commit your changes


C:\Users\LENOVO\Desktop\test_git\testing_git>git commit -m"modified README.md and created test.txt"
[main 86e62fd] modified README.md and created test.txt
 2 files changed, 1 insertion(+)
 create mode 100644 text.txt

to see the commits

C:\Users\LENOVO\Desktop\test_git\testing_git>git log
commit 86e62fdc5e39684921cf07a7b72776a0c48900a1 (HEAD -> main)
Author: ian-yitzhak <onyangoian71@gmail.com>
Date:   Mon Feb 1 22:53:06 2021 +0300

    modified README.md and created test.txt

commit 6f964e8489d55f27949cd18dfce250565ce01206
Author: ian-yitzhak <onyangoian71@gmail.com>
Date:   Mon Feb 1 22:40:31 2021 +0300

    create README.md file

After all the set up now lets push our project to github type git push origin main

C:\Users\LENOVO\Desktop\test_git\testing_git>git push origin main

Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 2 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (6/6), 506 bytes | 126.00 KiB/s, done.
Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:ian-yitzhak/testing_git.git
 * [new branch]      main -> main

Your project is now live on githb reload the browser and see the results shown.

see my github project here

Read more on version control

Posted in
programming

Post a comment

Your email address will not be published.

As the top software development company in Kenya, we can't wait to show you what we can do. Our team of talented designers and developers are passionate about creating beautiful, functional websites that not only look great, but also help your business grow.
0

No products in the cart.

× Get Help?