Journey to master your git skills (Beginners)

Let us take a journey together. By the end of the article, you would have mastered all the basic necessary skills required for a software engineer with version control.

Create a empty directory and initialize with git:

$ bash

mkdir new_project
cd new_project
git init

This would have created a hidden directory .git with config file inside it. For now, we will not create a remote repo or link the local will any remote origin. This will be cover as part of next tutorial in this series. To get the current state of the repo, use the commands below. It gives out detailed name and status.

$ bash

git branch -vvv
git status


If the branch is having changes (both 'staged' and 'unstaged'), it can be either flushed or saved in a stash. In case staged changes, do

$ bash

git restore --staged .

before doing

$ bash

git restore .

But if we would like to save the changes, it is better to stash them:

$ bash

git stash list
git stash push --include-untracked -m 'stash message'

To retrieve those changes, we can:

$ bash

git stash apply 1
# or
git stash pop


in case any untracked files and directories are present, it cannot be removed by restore command. It can be done using:

$ bash

git clean -fd


Now, switch to master / main and ensure that the local is having all the commits. Create a new branch from the base branch:

$ bash

git checkout main
git fetch -a
git pull --rebase origin main
git checkout -b dev/feature-name


$ bash

git reset --soft HEAD~2
git restore --staged .

$ bash

git reflog
git reset 293da63

Debugging git connectivity issues:

$ bash

git remote -v