STAND WITH UKRAINE 🇺🇦

Git workflow for solo web dev

Created:


Workflow tale

Once upon a time, a dwarf named Krevorook took a quest from a tree elf to build a static website and host it in CDN like Netlify. His journey was full of new discoveries… And befriending a ferocious beast, called GIT, was one of those. Following is a small account of the time they spend together.

After setting up the project, Krevorook created a new git repo. So he had his MAIN branch, where deployable (production) code lived.

git init
git add .
git commit -m 'init'

After creating a new Github repository, he added a remote.

git remote add origin https://github.com/user/repo.git
git push -u origin main

And git push worked well for him. He made a home page and deployed it.

Sometimes he bringed new files.

git add .
git commit -m 'added: .gitignore'
git push

Sometimes he polished existing ones.

git commit -am 'my message'

When Krevorook had forgotten to add some files or wrote an inaccurate message, he would correct himself.

git add .
git commit --amend -m 'new message'

But more often he just made trivial amendments.

git commit -a --amend --no-edit

He also has to make contact and about pages, which were obviously not production ready just yet. So he created a new branch DEV where the “actively developed” code lived.

git checkout -b dev
git push -u origin dev

He worked in sessions using pomodoro technique, 30 min work / 3 min break. One session usually took 2-3 hours followed by a minimum 1 hour break or change activity (nothing to do with coding or sitting).
At the end of each session Krevorook had the urge to commit, even without a meaningful message.

git commit -am 'up'

It was ok to use dummy commits, because he could always clean up history.

git rebase -i HEAD~3

More often than not he checked out the current state.

git status
git log --graph --decorate --pretty=oneline --abbrev-commit

It was very repetitive. Therefore Krevorook turned to his precious pet, Bash, who was of great help for that sort of thing.

# ~/.bash_aliases
alias gs='git status'
alias gl='git log --graph --decorate --pretty=oneline --abbrev-commit'
alias gc='git commit -m'
alias gca='git commit -am'

At last, pages were production ready and craved to be introduced to WWW.

And Krevorook joined DEV with MAIN.

git checkout main
git merge dev
git push

He has the website live with 3 pages: home, contact and about. But contact and about pages were fast made, and maybe he should try to make them better.

So he made two new branches, NEW-ABOUT-PAGE and NEW-CONTACT-PAGE, based on DEV, and worked tremendously on them.

git branch new-about-page dev
git branch new-contact-page dev

At some point the new contact page looked good, there was nothing to improve. So he joined the NEW-CONTACT-PAGE branch with DEV as a single commit. Then he pushed it all to production and cleaned up the repo, deleting the NEW-CONTACT-PAGE branch.

# make sure everything is good, some adjustment is needed?
git checkout dev
git merge --squash new-contact-page
git commit -m "merge new-contact-page"

# deploy
git checkout main
git merge dev
git push

# delete
git branch -d new-contact-page
git push origin --delete new-contact-page

And what about the about page?
Contarly to the contact page, the new about page looked not so good at all. So he decided to stick with the current one and moved on.

git branch -D new-about-page
git push origin --delete new-about-page

The end.


Commands used

Create a new local repository

git init

Displays the status of your working directory, (show modified files).

git status

Displays all commits in the current branch’s history

git log
git log --graph --decorate --pretty=oneline --abbrev-commit

Add a file to your next commit (stage)

git add [file]

Add all files to your next commit

git add .

Replaces that last commit with your new, improved commit.

git add .
git commit --amend -m 'new message'

Trivial amendments

git commit -a --amend --no-edit

Add, remove, or combine Git commits

git rebase -i HEAD~[num of commits]

Create a new branch (dev) and switch to it

git checkout -b dev

Switch to another branch (main) and check it out into your working directory

git checkout main

Create a new branch (dev) in a remote repository

git push -u origin dev

Create a new branch (feature) based on some existing one (dev)

git branch feature dev

Merge (join) a specified branch (feature) into your current branch (dev)

git checkout dev
git merge feature

Merge a specified branch (feature) into your current branch (dev) as a single commit

git checkout dev
git merge --squash feature
git commit -m "merge feature"

Delete a local branch (feature)

# safe delete
git branch -d feature

# delete without questions
git branch -D [failed-feature-branch]

Delete a remote branch (feature)

git push origin --delete feature