git basic command

By | October 22, 2022
clone from origin to local :
git clone <https://url.com>

show branch local :
git branch

show branch origin :
git branch -r

fetch : 
git fetch origin

pull :
git pull origin

create new branch : 
git branch <new-branch-name>

switch branch :
git checkout <branch-name>

create branch then switch to it :
git checkout -b <branch-name>

check status : 
git status

add single file :
git add <file>

add all : 
git add -A

commit : 
git commit -m "commit message"

push : 
git push -u origin <branch-name>

delete branch local :
git branch -d <branch name>
git branch -D <branch name>

delete branch origin :
git push origin --delete <branch-name>


undo commit but keep all changes (staged)
git reset --soft HEAD!;

undo commit and unstage all files
git reset HEAD~;

undo commit and completely remove all changes
git reset --hard HEAD~;

change commit message : 
git commit --amend