Gitting Gud in Collaboration with Git: A Casul’s Guide

ah yes, the real version control

Overview

example of git tree structure that has master, hotfix, release, etc branch (https://qph.fs.quoracdn.net/main-qimg-0ad347c0df53f7360754f2811f37969d)

Common Commands Tutorial

Setup

Initialization

git init 
#This command will clone the main branch of a repository
git clone <repository_url>
#This command will clone particular branch of a repository
git clone <branch_name> <repository>

Setup Identity

#This will setup the username
git config user.name <your_username>
#This will setup the email
git config user.email <your_email>

Connect your local git with repository git

git remote add <repo_identifier_on_local> <repository_url>

Add files to your change

#Add all files in the current working directory
git add .
#Add single file
git add <file_name>
#Add multiple files
git add <file1> <file2> <file3> <filen>

Commit a change

git commit -m "<commit_message>"
git commit --ammend -m “<new_commit_message>"

Save Your Progress Without Marking It

#Before jumping into another branch execute this command
git stash

#this will continue the last progress and drop it from the progress stack
git stash pop
#this will continue the last progress without dropping it from the progress stack
git stash apply
#this will throw away the last progress
git stash drop

Synchronize The Local Git

git pull origin <branch_name>
git fetch <remote-identifier> <branch>

Store Your Changes to Online Repository

git push origin <branch_name>#Usually I use this command to make local branch linked with the remote branch
git push -u origin <branch_name>
please avoid executing this command as possible

Create & Delete Branch

#Make new empty branch
git branch <new_branch>

#Make new branch that is derived from current working branch
git checkout -b <new_branch>
git branch -d <branch_name>#Force delete a branch
git branch -D <branch_name>

Move To Another Branch

git checkout <branch_name>

Check Commit History

git log

Undo Commit

https://blog.nakulrajput.com/wp-content/uploads/2018/10/Git-Reverting-Resetting.jpg
#Revert to a certain commit
git revert <commit_hash>
#Reset to a certain commit
git reset <commit_hash>

Combine Two Branches

https://i.stack.imgur.com/hUtiB.png
#Normal merge
git checkout <target_branch>
git merge <source_branch>
#Merge with squash
git checkout <target_branch>
git merge --squash <source_branch>
#Rebase
git checkout <source_branch>
git rebase <target_branch>
git checkout <target_branch>
git merge <source_branch>

Git Flow in Software Engineering Project

Git Flow in PPL 2021
our backend branches
commit examples

References