Post

Intro to Git

Intro

Git is the most popular version control system in the world. It allows you to track changes in your code, revert to previous versions, and collaborate with others.

The Basic Workflow

The most common way to use Git involves three main stages: the Working Directory, the Staging Area, and the Repository.

1. Initialize a Repository

If you are starting a new project (not your blog, which is already a repo), you run:

1
git init

2. Check Status

Before you do anything, it’s good to see what files have changed, you run:

1
git status

The “Big Three” Commands

To save your work to internet (GitHub, GitLab, Bitbucket), you will almost always run these three commands in order.

Step 1: Add (Stage)

Tell Git which files you want to save. To save everything, you run:

1
git add .

Step 2: Commit (Save)

Take a “snapshot” of your project. Always include a clear message about what you changed, you run:

1
git commit -m "Add my new Git tutorial post"

Step 3: Push (Upload)

Send your local saves to the internet (GitHub, GitLab, Bitbucket), you run:

1
git push origin main

Helpful “Life Saver” Commands

CommandWhat it does
git cloneDownloading an existing project.
git logShows your history of previous commits.
git pullDownloads the latest version from GitHub to your computer.
git checkout .Be careful! This undoes all changes since your last save.

Reference

This post is licensed under CC BY 4.0 by the author.

© 0xhanif. Some rights reserved.

Using the Chirpy theme for Jekyll.