Git - Terminal
- Creating
git init
=> Turn the selected folder into a git repository
git clone repoLink
=> Make clone of code in your local PC
touch .gitignore
=> Creates this file, Used to ignore files by GIT
- Commit
git status
=> Shows the changes made
git diff
=> Shows the change in that file
git add fileName
=> Move the file to staging area
git add .
=> To add all folder for staging area
git commit -m "message"
git log
=> Shows the previous commit
git log -n
=> Shows the last n commit
git show commitID
=> Shows the changes
git reset --hard HEAD^
=> Undo the latest commit
git reset --soft commitId
=> Undo commit but code change kept, commit ID of one before
git restore --staged fileName
=> Undo all changes made from the staged area
git restore fileName
=> Undo all changes made from an unstaged file
git commit --amend
=> Update change without creating a new commit
- Branch
git branch
=> Shows the Current Branch
git branch -a
=> List all Branch
git branch branchName
=> Make New Branch
git checkout -b branchName
=> Creates new Branch and Switch to that Branch
git branch -m newBranchName
=> Change Branch Name of the Current Branch
git branch -d branchName
=> Deletes Current Branch
git merge branchName
=> Merge the given Branch into the Current Branch
git checkout branchName/commitHashCode
=> Move to another Branch
git checkout master
=> Moves to Master Branch
- Push
git pull
=> Sync all commit from Remote & Local
git fetch
git push
=> Push your changes to remote branch from local branch, will ask your user ID
git remote -v
=> Shows URL of origin repository
git remote remove origin
git remote add origin repoUrl
=> Adds remote repository URL as origin
git config --global user.name "yourName"
=> To set your name
git config --global user.email "yourId"
=> To set your email
git config --global --edit
=> Directly edit from config file
git branch -M master
git push -u origin master
=> Push master branch in origin GitHub repository