Git Basics

Check Git version

    

git --version


    

Set user name and email

    

git config --global user.name "Your Name"
git config --global user.email youremail@example.com


    

Initialize repo

    

git init


    

Check status

    

git status


    

Stage file(s)

    

git add file-name


    
    

git add file-1 file-2


    

Stage all files

    

git add .


    

Commit files

    

git commit -m "Initial commit"


    

View log

    

git log


    

List branches

    

git branch


    

Create branch

    

git branch branch-name


    

Create branch and switch

    

git checkout -b branch-name


    

Switch branch

    

git switch branch-name


    
    

git checkout branch-name


    

Merge branches

    

git checkout branch-to-merge-into
git merge branch-with-changes


    

Delete branch

    

git branch -d branch-name


    

Discard changes to file

    

git checkout -- file-name


    

Unstage files

    

git reset HEAD file-name


    

Edit last commit

    

git commit --amend


    

Undo last commit

    

git reset --soft HEAD~1