DEV Community

Lucy Anyango
Lucy Anyango

Posted on

GIT WORKFLOW

## What is Git?

Git is a version control system used to track changes in files and maintain a history of a project.

It allows you to:

  • Track changes
  • Create versions of your work
  • Work with branches
  • Collaborate with others
  • Return to previous versions
  • Git vs GitHub

Git runs on your computer and tracks your project locally.

GitHub is an online platform where Git repositories can be stored, shared, and collaborated on.

## The Basic Git Workflow
Important workflow to understand is:

Working Directory

git add

Staging Area

git commit

Local Repository

git push

## GitHub

  1. Check your changes git status

Shows which files have been added, modified, or are waiting to be staged.

  1. Stage changes git add .

Moves your changes to the staging area.

  1. Commit changes git commit -m "Update project files"

Creates a saved version of the staged changes.

  1. Push to GitHub git push

Uploads your committed changes to the GitHub repository.

## Creating a Repository

Create a project folder and initialize Git:

mkdir my-project
cd my-project
git init

git init turns the folder into a Git repo.

## Connecting to GitHub

Connect your local repository to GitHub:

git remote add origin git@github.com:username/repository.git

Check the connection:

git remote -v

Then push the project:

git branch -M main
git push -u origin main

## Git Commands to Remember
Command Purpose

  • git status Check changes
  • git add . Stage changes
  • git commit -m "message" Save changes
  • git push Upload to GitHub

Remember this workflow:

EDIT

git status

git add

git commit

git push

GITHUB

Once you understand this cycle, you have the best foundation for using Git and GitHub effectively.

Top comments (0)