Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 18

Git Basics

Sudipto Das
What is Git ?

Git is a free and open source distributed version control


system designed to handle everything from small to very
large projects with speed and efficiency.
Creator

Linus Benedict Torvalds


Topics

Git init Git attribute


Git status
Git stash
Git author
Git reset
Git commit
Git amend Git alias
Git branches Git rebase
Git workflow Git merge vs git rebase
Git log Git cherry-pick
Git merge
Fetch deleted branch
See merged branches
Git clone
Git tag
Git origin Git coauthor
Gitignore Gitmoji
Git init & Git status

Initialization: git init


Status : git status
Git Author

git config --global user.name "YOUR NAME"


git config --global user.email "YOUR@EMAIL.com"
Git Commit

Add file: git add <fn>


Commit : git commit
Commit single line: git commit -m “message”

wip - the prefix wip indicates work in progress.


exp - experimental branch for dev purpose.
feat - adding a new feature.

Conventional commits
https://www.conventionalcommits.org/en/v1.0.0/
Git Amend

git commit --amend


Git Branch

Create new branch : git checkout -b <bn>


List of branch : git branch / git branch -a
Checkout to another branch: git checkout <bn>
Soft delete branch: git branch -d <bn>
Hard delete branch: git branch -D <bn>
Delete origin branch : git push origin --delete <bn>
Clone origin branch : git checkout -b <bn> origin/<bn>
Rename branch: git branch -m <bn> <new bn>
Git Workflow

Master

Stage

Develop

Feature

Bugfix

Hotfix
Git Log

See commit history: git log


One line: git log --oneline
Stat : git log --stat
Git merge

git merge <bn>


Git merge --squash
Git clone

Add SSH Key : ssh-keygen -t rsa -b 4096 -C "YOUR@EMAIL.com"


git clone <repo url>
Git Origin

Push to remote : git push origin <bn>


Push to remove and remember :git push origin -u <bn>
Push remembered : git push
Pull : git pull
Set remove url : git remote add origin <url>
Update remove url : git remote set-url origin <url>
See remote url: git remote -v
Gitignore

.gitignore

git rm -r --cached .
git add .
Git commit -m “Gitignore fixed”
Git stash

git stash
git stash push -m “Named stash”
git stash push -u -m “Named stash”
git stash list
git stash apply 0
git stash pop 0
Git reset

git reset <commit>


git reset -soft <commit>
git reset -hard <commit>
Git conventions

Atomic Commit
Do not push to master directly
Don’t commit dependencies into source control
Configure the git authorship
Write descriptive and meaningful commit Don’t commit local config files into source control
Commit only related work Use reference number in your commit
Anything in the master branch is deployable Defined git workflow
Open a pull request at any time Don't mix refactoring with new feature
One Commit, one change
Use pull requests
One pull request, one concern
Do not commit generated file
Do not commit secret keys

You might also like