DEV Community

Damaa-C
Damaa-C

Posted on

Understanding Git: How it tracks, pushes and pulls code on Ubuntu

Before we dive into how Git tracks changes and handles pushing and pulling code, let’s first understand what Git is, what it does, and how it works together with GitHub.

What is Git?

Git is a version control system. This means it works on your computer first, even without internet. Think of it as a time machine for your code.

Git allows you to track changes to your files, save versions of your project, revert to earlier states and collaborate safely with others.
GitHub, on the other hand, is a remote platform where Git repositories are stored online.

Installing Git and linking it to GitHub

Before installing Git, first go to your web browser and create a GitHub account. Go to your terminal after creating the account.


Step 1: Install Git

sudo apt update

Install Git:

sudo apt install git -y

Verify Git installation:

git --version

`Shows Git is successfully installed on Ubuntu.`

Enter fullscreen mode Exit fullscreen mode

Step 2: Configure Git Identity

Set your name:

git config --global user.name "Your_Name"

Set your email:

git config --global user.email "your_email@gmail.com"

Check configuration:

git config --list

user.name=Your Name
user.email=your_email@gmail.com`
Enter fullscreen mode Exit fullscreen mode

Shows Git configuration including username and email.

user.name=Your Name → Git knows who is making commits. This name appears in the commit history.

user.email=your_email@gmail.com → Git associates your commits with this email. It must match your GitHub account email.
Enter fullscreen mode Exit fullscreen mode

This confirms Git is configured correctly. Without this, Git will not track who is making changes, and commits may not appear properly on GitHub.

Step 3: Create SSH Key and Link to GitHub

Generate a secure SSH key:

ssh-keygen -t ed25519 -C "your_email@gmail.com"

Start SSH agent:

eval "$(ssh-agent -s)"

Add your key to the agent:

ssh-add ~/.ssh/id_ed25519

Display your public key:

cat ~/.ssh/id_ed25519.pub

Test the connection:

ssh -T git@github.com
Enter fullscreen mode Exit fullscreen mode

Example of wrong input:

ssh -T git@github.com
`Permission denied (publickey).`
Enter fullscreen mode Exit fullscreen mode

Correct output:

Hi username! You've successfully authenticated, but GitHub does not provide shell access.

Shows a successful authentication with GitHub via SSH.

Step 4: Create a GitHub Repository

Create a new repository on GitHub and do not initialize with README. This will be your remote repository.

Step 5: Create Local Project Directory

Create a new folder and navigate into it:

mkdir beginner-git-project
cd beginner-git-project

Shows folder creation and navigation.
Enter fullscreen mode Exit fullscreen mode

Step 6: Initialize Git

git init

Shows that the folder is now a Git repository.
Enter fullscreen mode Exit fullscreen mode

Step 7: Create a File

Create a README file:

touch README.md
echo "# Beginner Git Project" >> README.md

Check repository status:

git status

Example of wrong input:

git statuz

Output:

`git: 'statuz' is not a git command. See 'git --help'.`
Enter fullscreen mode Exit fullscreen mode

Step 8: Stage Changes

git add .

Check status:

git status

Shows staged files ready to commit.
Enter fullscreen mode Exit fullscreen mode

Step 9: Commit Changes

git commit -m "Initial commit"

Example of wrong input:

git commit -m Initial commit

Output:

`error: pathspec 'Initial' did not match any file(s) known to git`

Correct syntax requires quotes around the commit message.
Enter fullscreen mode Exit fullscreen mode

Step 10: Connect Local Repo to GitHub

Add the remote repository:

git remote add origin git@github.com:username/beginner-git-project.git
git remote -v

Shows the remote repository connection.
Enter fullscreen mode Exit fullscreen mode

Step 11: Push Code to GitHub

Rename branch to main:

git branch -M main

Push your code:

git push -u origin main

Example of wrong push command:

git push
`fatal: No configured push destination.`

This occurs if the remote wasn’t added.
Enter fullscreen mode Exit fullscreen mode

Step 12: Pull Changes from GitHub

git pull origin main

Downloads the latest changes from GitHub and merges them into your local project.
Enter fullscreen mode Exit fullscreen mode

Step 13: View Project History

git log

Exit the log view:

q
Enter fullscreen mode Exit fullscreen mode

Why Git Matters (Data Science & Data Engineering)

  • Track notebooks & pipelines

  • Collaborate safely

  • Revert mistakes

  • Production-ready workflows

Git allows developers, data scientists, and engineers to track code changes, collaborate safely, and recover from mistakes. By understanding each command and its purpose, beginners can confidently manage projects and work professionally using Git and GitHub.

Learning Git on Ubuntu empowers you to manage projects confidently and collaborate effectively. Whether you’re working on ETL pipelines, machine learning models, or data analysis notebooks, Git ensures your work is organized, secure, and scalable.

Top comments (0)