GitHub Workflow

  1. Git
  2. GitHub
  3. Repository
  4. Commit
  5. Branch
  6. Push
  7. Pull
  8. Clone

Difference Between Git and GitHub

Git and GitHub are often mentioned together, but they serve different purposes. Without understanding this difference clearly, work can lead to serious workflow problems later on.

  • Git: A version control system that runs locally and tracks code history.
  • GitHub: A platform that hosts Git repositories online and makes team collaboration easier.
  • Git cannot work without GitHub, and GitHub cannot work without Git.

Check if Git is Installed

Before starting to work with Git, the first and mandatory step is to check whether Git is installed on your system. No Git commands should be run without this check.

  • If Git is installed, you will see output like git version 2.xx.x and can move to the next step.
  • If an error occurs like command not found: git, Git is not installed. In this case, Git should be installed from the official website.
bash
git --version

Set Git User Information

Git associates every commit with a user. Therefore, before using Git, you need to tell Git who the commits are made by. These details:

  • Are set once
  • Apply to all projects
  • Are permanently visible in the commit history

Set Username

This sets the name that will appear in commits. It can be your real name, a nickname, or an internal team identifier.

bash
git config --global user.name "Sezer Gec"

Set Email Address

This sets the email that will appear in commits. It is recommended to use the same email as your GitHub account.

bash
git config --global user.email "example@gmail.com"

Create Local Project Folder

Git does not work alone. It always works within a folder, which is considered the project directory. All project files reside here. In this step:

  • Only a folder is created
  • There is no Git repository yet
  • No GitHub connection yet
bash
mkdir example-project
cd example-project

Initialize Git Repository

At this point, we have a project folder, but Git is not tracking it yet. To make this folder a Git repository, we need to explicitly tell Git to track it. The following command turns the current directory into a Git repository. This process is entirely local and does not require internet connection.

  • A hidden folder called .git is created
  • All commit history is stored here
  • The project is now tracked by Git
bash
git init

Add First File and Make First Commit

After initializing the repository, Git can track the folder, but there are no files to track yet. Git only records changes and files.

The next step is to add the first file and save its state to Git history. This process is called a commit.

Create First File

For example, create a simple README file. This file explains what the project does and is usually present in almost every project.

bash
touch README.md

Check File Status

Git automatically tracks the status of files in the repository. Use the following command to see which files are untracked. At this stage,README.md will appear as untracked.

bash
git status

Add File to Stage

To tell Git to include this file in the next commit, add it to thestage area. To add a specific file: git add README.md

bash
git add .

Make First Commit

Files added to the stage are now ready to be committed. A commit saves the current state of the project to Git history.

bash
git commit -m "Initial commit"

Create Repository on GitHub

At this stage, the local Git repository is pushed to GitHub. GitHub is the platform where the code is stored and shared online.

  • Local code is pushed to GitHub
  • The project is now backed up online
  • Ready for team collaboration

After logging into GitHub, click New and follow the rules to create a remote repository.

  • Repository Name: Should match the project folder name
  • Description: Optional project description
  • Public / Private: Choose according to need
  • README, .gitignore, license: Do not check these because they are already created locally

Connect Local Repository to GitHub

At this stage, the local Git repository is connected to the empty GitHub repository. After this, code can be pushed to GitHub.

  • Link between local and remote repository is created
  • No code is pushed yet
  • Only connection is established

Define Remote Repository

Using the GitHub repository URL, a remote called originis defined. origin represents the main repository on GitHub.

bash
git remote add origin https://github.com/USERNAME/example-project.git

Check Remote

Verify that the remote has been added correctly. If everything is correct, origin will appear in the list.

bash
git remote -v

Standardize Branch and First Push

At this stage, the local branch is aligned with GitHub standards and code is pushed for the first time. After this, local and remote repositories are synchronized.

  • Default branch is set to main
  • Local branch is pushed to GitHub
  • Upstream tracking relationship is created

Rename Branch to main

Some systems may use master as the default branch. This command renames it to main.

bash
git branch -M main

First Push

Push the local main branch to GitHub. The -uflag sets it as the default tracking branch. After a successful push, project files are visible on GitHub.

bash
git push -u origin main

Using .gitignore

By default, Git tracks all files in the project folder. However, some files should not be sent to GitHub. To ignore these files, use a .gitignore file.

Create .gitignore

Create a file named .gitignore in the root of the repository.

bash
touch .gitignore

.gitignore Content

Below is a common example for Node.js projects. You can add files or folders you do not want to push to GitHub.

text
node_modules/
.env
.next/
dist/
build/
.DS_Store
npm-debug.log*
yarn-debug.log*
yarn-error.log*

Daily Git Workflow

Once the repository is connected to GitHub, Git becomes a natural part of the daily development process. Every change follows a sequence and is pushed to GitHub. This workflow is standard for individual and team projects.

Modify Files

Any changes in project files are automatically detected by Git, but remain local until committed.

Check Changes

Use the following command to see which files have been modified. Modified files appear as modified.

bash
git status

Add Changes to Stage

To commit changes, they must be added to the stage area. Usually, all changes are added.

bash
git add .

Create a New Commit

Changes are saved to Git history with a clear commit message explaining what was done.

bash
git commit -m "Update README content"

Push Changes to GitHub

Commits are sent to the GitHub repository. Since upstream is set, only git push is needed.

bash
git push origin main

Clone and Update Project

Steps to download a GitHub project to your local machine or synchronize an existing project with the latest version on GitHub. Use git clone for the first download, and git pull to keep it up to date.

Git Clone

Used to download a repository from GitHub for the first time. This retrieves all files and commit history to your local machine.

bash
git clone https://github.com/USERNAME/example-project.git

Git Pull

Used on an already cloned project to fetch changes from GitHub.

bash
git pull origin main
On This Page
copyright © 2026 - sezergec.dev