DEV Community

Wendy Ochieng
Wendy Ochieng

Posted on

A beginner's understanding of the Git Workflow

Git

This is a version control system that tracks changes to files in a project. It's a software that recalls the exact files that were edited, when these changes were made and by whom(if it's a team project) and stores the previous versions of the files.
It's quite useful especially for large projects with multiple developers.
Git saves your files locally(in your machine) and you can store your code online or share it with others through github, gitlab or bitbucket.

Git Core Concepts

1. Repository(Repo)
This refers to a project and its entire history of changes. It can be local or remote.

2. Git commits
These are like snapshots of the entire projects that records all the tracked changes in your directory. Git can sometimes bundle all the changes to a project from one version of the repository to another, instead of just blindly copying the entire directory every time you commit-it maintains a history of which commits were made when.
A new commit might have another commit above it, like a parent commit, which references which commit it was based off of.

3. Git Branches
These are simply pointers to a specific commit. They are independent lines of development that allows you to work on features or fixes without affecting others.

Git Workflow Diagram.com

  • In the image, we have a branch called newimage that now refers to commit C1.

To create a branch called newimage and immediately switch to it, we can use this code;

git checkout -b newimage

To prevent having many branches, it's better to divide your work.

4. Merge
Merging brings changes from one branch into another.

Basic Git Workflow

Common commands used to manage projects and upload your work to github.
1. Working Directory
This is the local folder where you create, open and edit files. This directory can be observed but changes are not automatically recorded.

2. Staging Area
This is where you select the changes you want to include in your next commit. You may choose specific files or lines of code you want to bundle together before saving.

3. Local Repository
It's the internal git database inside the project folder. It's where you commit the staged changes and git permanently saves it as a secure snapshot in your local history.

4. Remote Repository
This is where commits are pushed so others can access them, eg Github.

Note;

  • You push projects from your local machine to Github
  • You pull projects from Github to your local machine

Conclusion

The workflow looks like this in a nutshell;
┌──────────────────┐
│ Working Directory│
│ (your files) │
└─────────┬────────┘

│ git add
│ git add.

┌──────────────────┐
│ Staging Area │
│ (index) │
└─────────┬────────┘

│ git commit -m "message"

┌──────────────────┐
│ Local Repository │
│ (your computer) │
└─────────┬────────┘

│ git push origin main

┌──────────────────┐
│Remote Repository │
│ GitHub / GitLab │
└─────────┬────────┘


│ git pull origin main
│ git fetch

└───────────────────────

  1. Edit files in the Working Directory.
  2. Use git add to move changes to the Staging Area.
  3. Use git commit to save a snapshot in the Local Repository.
  4. Use git push to send commits to GitHub.
  5. Use git pull to get other developers' latest changes.

Top comments (0)