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@example.com:my_project.git
git push -u origin master

For the bitbucket repository, fourth command can be changed as

git remote add origin https://username@bitbucket.org/username/repo.git

  • 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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s