DEV Community

Shaban Ibrahim
Shaban Ibrahim

Posted on

HOW TO GIT IT

Git Logo

UNDERSTANDING GIT AND GITHUB

You remember the first day you tried your hand in tech, maybe in software engineering, data science, web development or data engineering? Your trainer or technical mentor insisted that you have a GitHub account, and they made it a mandatory requirement for you to have one as industry best practice. I am sure you were wondering what GitHub is and how it will be important in your tech journey.

Many moons later, you came to realise that actually Github is like a treasure chest for any tech person, although before you got the grasp of it, you were confused and didn't understand how it works.

GitHub is an online platform that hosts git repositories, among many other platforms such as Gitlab and Bitbucket. It helps users to store, share and collaborate on code. Basically, the treasure chest of coders.

Create Github account

To create Github account,click here

Now what is Git?

Git is simply a time machine for your code. This means it is a tool that helps you track changes in your code over time, whereby you can easily save different versions of your work, go back to earlier versions if something breaks, and collaborate with others without overwriting each other’s work. This makes git a version control system.

Installing Git

To install Git, you can click the link

What are some of the components of Git?

We need to understand some of the components of Git and what they mean before understanding how to navigate inside or around it.
Some of the main components of Git are;

  • Repository (Repo)

  • Working Directory

  • Staging Area

  • Commit

a) Repository

This is a particular project in Git that is being tracked. It contains your files, change history and git configuration, all of which are contained in the .git folder.
For example

my-project/
|-- app.py
|--README.md
|--.git/
Enter fullscreen mode Exit fullscreen mode

How to Create Your Repository on git

  • Create a project folder
    mkdir my-project

  • Navigate into your project folder by
    cd my-project

  • Initialise Git by
    git init

b) Working Directory

The working directory is the folder on your computer where you:Write code, Edit files, and delete or add files.

Git continuously checks this directory for changes.

You can track changes in *Git by* git status

c) Staging Area

Now this is the area where you instruct, and direct Git to save a particular change that you might have made in your code, because not all changes are saved automatically, you have to choose what to save.

To stage a specific file:

touch app.py
touch README.md

To stage everything: git add .

d) Commit

This is a snapshot of your code at a specific point in time, and commits are characterised by unique id, message describing the change and a time stamp. Call them Checkpoints.

To add a commit: git commit -m "Add the logic describing the change"

To see past commits: git log

Below are the image demonstrations on how to go about operating git

Image 1

Image 2

Connecting Git to GitHub Remotely

After creating your repository on Git you will need to connect it remotely to your GitHub account.

In your Github account, you will need to create a new repository in which you will name.
An SSH key will be created in the form of:
git@github.com:Shabex/Data-Eng.git

Copy the SSH Key and use the following syntax you can link your git to GitHub remotely:
git remote add origin git@github.com:Shabex/Data-Eng.git

Pushing Your Code

This is how you send your local commits to the remote repository in Github
git push -u origin main
After pushing your code, they become visible on GitHub

Pulling Your Codes

This is how you send your changes from the remote repository to my local computer
git pull origin main
This comes in handy when you are working on a shared project, switching computers or updating your local copy of the file.

Image 3

Image 4

Top comments (0)