Useful Git commands, my daily basis list!

Start a new repo

git init
git add your_files (multiple files are comma separated)
git commit -m “First backup of my amazing idea”
git remote add origin
git push

Remember username and password

git config –global credential.helper store
git pull

Switch branches

git checkout branch_name

Checkout remote branch (you dont have it on local)

git fetch origin ‘remote_branch’:’local_branch_name’

Create new branch

git checkout -b feature_branch_name

Edit, add and commit your files.

git push -u origin feature_branch_name

Checkout remote branch (that not see on local)

git checkout –track origin/feature_branch_name

Show only local branches

git branch

Show only remote branches

git branch -r

SHOW ALL BRANCH (local and remote)

git branch -av


The branch you want to update

git checkout master

Get all the latest changes

git pull origin master

Merge this branch with one you want to update (step 1)

git merge test

Push your changes

git push origin master

Delete branch

Delete branch locally

git branch -d localBranchName

Delete branch remotely

git push origin –delete remoteBranchName

Stash/unstash changes

git stash
git stash pop

Show files in last stash

git stash show

Discard unstaged changes

git stash save –keep-index –include-untracked

Show unpushed Git commits

git log origin/master..HEAD
git diff origin/master..HEAD

Inspect a commit (list only file names)

git show –pretty=”” –name-only hash_id

Undo add file

git reset file_name

Undoing the Last Commit

Note the –soft flag: this makes sure that the changes in undone revisions are preserved.

git reset –soft HEAD~1

If you don’t want to keep these changes, simply use the –hard flag.

git reset –hard HEAD~1

File mode

git config core.fileMode false
git config –global core.fileMode false

Remove a folder from git tracking

git rm -r –cached path_to_your_folder