Skip to content

Git Workflow

Git is used for version control and pushing ready-to-deploy applications to the server automatically. It's very easy to use, but sometimes I forget the exact commands for something. I mostly use Git through VS Code's Source Control extension, but there are still plenty of times I use it through the terminal.

Setting up a new repository

Creating the repository

In the terminal, navigate to the folder you want to use for your repo. The following turns the folder into a Git repository:

Bash
1
git init

Staging files

Staging a file means to designate it as part of the next commit. The next time you make a commit, the staged files will be included in their current state at the time.

When you first create a new repo, it's common to stage all files within the repo for a commit:

Bash
1
git add .
Note

The . means "all" or "everything" --- all files and folders that aren't in a .gitignore will be staged.

Making a commit

A commit is the most fundamental part of using Git and is the primary functionality for version control. Commits are, essentially, committing to the changes you've made --- but they aren't irreversible.

A commit is like a snapshot of your files at that time. You are able to, at any time, revert back to a commit; this is called cherry picking. Doing so changes all your local files back to what they were at the time of that commit. (New files that were created after the commit will be removed.)

I do most of my commits through VS Code, but they can easily be done through the terminal:

Bash
1
git commit -m "Initial commit"

Your commit message can be anything, but it's convention to list the changes the commit makes.

Tip

It's a good idea to make a commit before you make any huge changes to your repo. That allows you to effectively save your progress and revert back to the last "stable" version if necessary.

Connect to GitHub repository

You often will want to utilize a remote repository for projects. This can be done very easily via GitHub:

Bash
1
2
git remote add origin
https://github.com/vixenbee/Honeycomb.git

Push to GitHub

I'm using a remote repository to handle updates to my server. When I'm ready to make updates live, I push it to my remote repo on GitHub via Git:

Bash
1
git push -u origin master

I've switched to doing my pushes through VS Code, as well.