Git Commands Every Developer Should Know
For initialize git in a folder
git init
For set a user name and email as user globally for all repository
git config — global user.name “xyz”
git config — global email ”abc@gmail.com”
For set a user name and email as user for individual repository
git config user.name “xyz”
git config email”abc@gmail.com”
To see the user name and email and other configure information's
git config — list
To see the the current status of your project or folder or working directory
git status
To stage a single file from working directory to staging area
git add cold.txt
To stage all file from working directory to staging area
git add — all
git add .
To commit
git commit -m “two file added”
To see all commit details
git log
To see all commit in short
git log — oneline
To see a single commit status
git checkout (commit number)
To create a new branch
git checkout -b
Switch to master branch from current branch
git checkout master
To see difference from last stage to new stage
git diff
To see the specific commit status
git show (commit number)
To see difference between two commit
git diff old commit number new commit number
To see difference between local repository & working directory
git diff — staged
To remove or delete a file from local repository but it will track
git rm file_name
To remove or delete a file from staging area it will not track any more
git reset HEAD file_name
Push anything to current branch
git push
Push to any branch
git push branch-name
Clone a repo
git clone (clone_link)
git clone (clone_link) new _name
For fetching branches
git fetch
git fetch -all
Pull data from current branch
git pull
pull from any branch
git pull branch-name
To see the all branch list
git branch
Switch to any branch from current branch
git checkout branch-name
To create a new branch
git checkout -b branch-name
To merge current branch to master
git merge branch-name
To Delete a branch
git branch -D branch_name
To Delete or hide or remove last action/status from a file
git stash
To get back before stashing status
git stash pop
git stash apply
To get all stash list
git stash list
To get a single stash list
git stash pop (stash_sl_number ex:stash@{0})
To check what will happen if you run
git clean -f
git clean -f -n
To delete a unstaged or untacked file
git clean -f
To create a gitignore file
touch .gitignore