L&D series: Just a simple Git commands

Ferawati Hartanti Pratiwi
2 min readMay 19, 2021
https://ohmygit.org/assets/images/oh-my-git.png

Learning and Development chapter 15.

Configuration

git config –global user.name "YOUR_NAME"

git config –global user.email "EMAIL_ADDRESS"

Examples :

git config –global user.name "Ferawati Hartanti Pratiwi"

git config –global user.email "mpermperpisang@gmail.com"

Initialization

git init REPOSITORY_NAME

Example :

git init mpermperpisang_learning_and_development_series

Add remote server

git remote add origin REMOTE_SERVER_URL

Example :

git remote add origin git@github.com:mpermperpisang/mpermperpisang_learning_and_development_series.git

Clone repository

  • git clone SSH_URL
  • git clone HTTPS_URL

Examples :

git clone git@github.com:mpermperpisang/mpermperpisang_learning_and_development_series.git

git clone https://github.com/mpermperpisang/mpermperpisang_learning_and_development_series.git

Check branch name

git branch

Create branch

git checkout -b BRANCH_NAME

Example :

git checkout -b master/mpermperpisang

Rename branch

git branch -m NEW_BRANCH_NAME

git push origin -u NEW_BRANCH_NAME

Examples :

git branch -m master/mpermperpisang_main

git push origin -u master/mpermperpisang_main

Delete branch

  • git branch -D BRANCH_NAME
  • git push origin --delete OLD_BRANCH_NAME

Examples :

git branch -D master/mpermperpisang

git push origin --delete master/mpermperpisang

Move to some branch

git checkout BRANCH_NAME

Example :

git checkout master/mpermperpisang

Pull latest code from another branch

git pull origin BRANCH_NAME

Example :

git pull origin master

Check modified file

git status

Reset modified file

  • git reset FILE_PATH
  • git reset --hard HEAD
  • git checkout .

Example :

git reset /Users/home/mpermperpisang/project/mpermperpisang_learning_and_development_series/README.md

Stashed modified file

  • git stash
  • git stash pop
  • git stash list
  • git stash drop

Adding file before commit

  • git add FILE_PATH
  • git add .

Example :

git add /Users/home/mpermperpisang/project/mpermperpisang_learning_and_development_series/README.md

Commit added file

  • git commit -m "COMMIT_MESSAGE"
  • git commit --amend -m "COMMIT_MESSAGE"

Examples :

git commit -m "commit without ammend"

git commit --amend -m "commit with amend will rename latest commit message"

Push commited file to remote server

  • git push origin BRANCH_NAME
  • git push origin BRANCH_NAME_1:BRANCH_NAME_2
  • git push origin HEAD

Examples :

git push origin master/mpermperpisang

git push origin master/mpermperpisang:master/mpermperpisang_main

List of revision and last modified file

git blame FILE_PATH

Example :

git blame /Users/home/mpermperpisang/project/mpermperpisang_learning_and_development_series/README.md

--

--

Ferawati Hartanti Pratiwi

QA (Quality Ambassador) | mpermperpisang official Medium account