Evaluating All Git Manuals as if They Were Jane Austen Books

Oh god, I hope I didn’t get sued under IP infringement for this title.

Zakiy Saputra
5 min readApr 5, 2021
Source — wikipedia.org

Hello everyone! In this article, I’m going to explain some commonly used commands on Git services! Before we head on to the manuals though, let’s understand the fundamentals first, shall we?

What is git?

Git is a Distributed Version Control System (DVCS) that records changes to a list of files over time so that you can recall specific versions later. Other than DVCS, there is also Local Version Control System (LVCS) and Centralized Version Control System (CVCS). Compared to LVCS and CVCS that stores history and versions of files only in local/server and are prone to lose everything, DVCS keeps history in both local and server which secures your files. Since team coding involves a diverse group of individuals with different tasks and objectives, a DVCS allows each programmer to code with less risk to obstruct their teammate's job with less risk of data loss from self or server — since changes are saved on both sides.

Illustration of DVCS — source: https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control

After a brief explanation about git themselves, below I'm going to list some commands that are commonly used while using Git services such as Gitlab or Github. Note that all commands are the same under different Git services, so don’t be afraid that this manual won’t work if you’re not using Github!

Git Manuals

Git clone

How to use this command:

git clone <your-git-project>

When to use this:
At the start of your project. This can be done from an existing remote repository on Git services

Git push

How to use this command:

git push -u origin <branch-name>example:
# edit some files first
git add . // "." means: add all changes
git commit -m "[Insert commit message here!]" // this will be the push message in your Git repository!
git push -u origin master // push to master branch!

When to use this:
When you’re pushing changes you’ve committed to Git services repository. Don’t forget to do the previous commands before using push such as shown in the example!

Git pull

How to use this command:

git pull origin <branch-name>

When to use this:
To obtain changes from another branch by another person to your local branch. When there have been changes from the main branch such as staging or master, it is imperative to pull from said branch before merging to avoid errors or losses.

Git merge

How to use this command (merge another branch to your current branch):

git merge <another-branch>

When to use this:
When we are merging a branch to another branch. I suggest not to use this command and do merge manually from Gitlab merge page instead, however. This way, other teammates can review and assess your changes before merging.

Git merge board example in Gitlab
By doing it on Gitlab instead by command, friends can analyze your commits and point out crucial infos!

Git rebase

How to use this command:

// rebase another branch to your current branch
git rebase <another-branch>
// shows interactive list to pick desired commits from another branch to your current branch
git rebase -i <another-branch>

When to use this command:
When you want to merge branches without actually merging for several reasons (cleaner commit history, etc), rebase can be used as an alternative where your commits are integrated with commits from the source branch.

Git revert

How to use this command:

// the default flag. changes HEAD and index
git reset --mixed
// changes HEAD but not index. resetted commit will shows as staged under git status
git reset --soft
// same as --mixed, but all changes from resetted commit and your unsaved commit are lost
git reset --hard

When to use this command:
Add another commit called reset where changes after the set point are unrolled. This way, accidental pushes can be reverted back to the previous point.

I accidentally merged to master (approved and merged by my friend)! Thanks to Git revert, this problem is avoided.

Git remote
How to use this command:

// shows lists of connection your local are connected with
git remote
// link your remote repository with local
git remote add [name] [repository]

When to use:
This is pretty self-explanatory, isn’t it?

Git branch
How to use this command:

git branch

When to use this:
When you need to make sure which branch you’re at or to show branches saved in your local devices.

Git checkout
How to use this command:

// use flag '-b' if branch-name doesn't exists yet
git checkout -b <branch-name>

When to use this:
When you need to commit in another branch.

Git stash

How to use this command:

// stash an uncommited changes from current branch
git stash
// apply changes in stash and remove them from stash list
git stash pop
// apply changes in stash but keep them in stash list
git stash apply
// shows list of stash
git stash list
// removes all stash in list
git stash clear

When to use:
Have you ever wrote your code while still on branch ‘one’ when you’re supposed to push said codes on branch ‘two’? Well, you’re in luck! With git stash, these changes can be saved and pulled back later on branch ‘two’ without actually having to undo all changes and redo it after switching branch (I’ve actually done this. 0/10 not recommended).

So there we have it, an evaluation and guide on commonly used commands in Git services! Understand it well, and now you’re one step closer to be a master in Git! (I repeat you guys, don’t do the same mistakes as I do when I didn’t know these commands exist). See you in my next article!

--

--