My Git Workflow for Personal Projects
Tags: git, github, gitlab, bitbucket
Published: 2021-06-27 07:40:46

This post is targeted at all my friends out there who are looking to pick up Git. It should be a sufficient guide if you are looking to upload personal projects to code repositories like GitHub. If you are working on a project that requires collaboration with a team, do check out your team's docs on their workflow strategies instead.

## What is a code repository?

An organised storage for your project's source code.

## What is Git?

A version control system ([source](https://www.atlassian.com/git/tutorials/what-is-git)).

## Why upload your project to a code repository like GitHub?
 
1. **Version control** - Code repositories like GitHub are built such that you can efficiently retrieve different versions of your source code. 
2. **Collaboration** - Code repositories tend to have features like version control and code review which allow for ease of collaboration. If your code is open-source, it's also an invitation to people from around the world to comment and collaborate on your work.
3. **Online portfolio** - It's a place where you can showcase the work you have done.

## My Git workflow

Here's how I most commonly use Git for my projects.

### Creating a new project

1) Create a new project on the code repository website.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6sk0hnahk3habpg6yrqx.png)
<figcaption>For GitHub, you can do so by clicking "New repository" on the right of the navbar, beside your profile picture</figcaption>
 

2) Upon creating your project, you should see instructions on how to link your local project up with the remote one.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m8c8b358gxus7vtxdb1h.png)

The local project is the local version on your computer, while the remote project is what you uploaded to the code repository. It's similar to when you upload a file onto Google Drive. The changes you make in the local copy of your file will not be reflected in the Google Drive copy until you upload the file again. Similarly, if someone makes a change in the Google Drive copy, it will not be reflected on your local copy until you download the new file version.
 

### Pushing updates to your project

1) Make changes on your local project.

2) To upload the new changes:
_i. Add the changed files which you want to upload by doing one of the following:_
```
// To add a single file /path/to/filename.js
git add /path/to/filename.js

// To add all files in the folder /path/to/
git add /path/to/*

// To add all files that have been changed
git add .
```
For MacOS users, you can download [scmpuff](https://github.com/mroth/scmpuff), which will number off files that have been changed. You can then do something like:
```
git add 1-5
```

_ii. Commit the added files_

```
git commit -m "feat: added some new feature"
```

The last parameter in the above command is the commit message. Do write a meaningful commit message so you can easily tell what changes this commit consists of. The [AngularJS Commit Message Conventions](https://gist.github.com/stephenparish/9941e89d80e2bc58a153#format-of-the-commit-message) is a great place to start with how you can structure your commit messages.

_iii. Push the new commits_

```
git push
```

This step pushes your new commits to the remote project.

---

If you do try out this workflow, do let me know if you face any problems and I will update the content accordingly. If you are a comfortable Git user, I'd like to know how your workflow differs as well!