Git commands that I use most frequently

Following are the git commands that I have required many times. So I have compiled them here.

  • Adding remote repository and doing an initial push

git init
git add *
git commit -m "My initial commit message"
git remote add origin
git push -u origin master

For the bitbucket repository, fourth command can be changed as

git remote add origin

  • Removing a file from remote repository which has been deleted from local repository

git commit -a -m "Message"

-a flag will delete the files which have been deleted on local repository.

  • Undo git add a file if git commit is not done

git reset HEAD filepath