GITSome daily and useful GIT commands

Some daily and useful GIT commands

Initial Steps ( this is for creating a PUBLIC git repository on GitHub : anyone can have access to this )

  • As suggested this post is for setting up a PUBLIC git repository on GitHub ( and local one on Ubuntu )
  • Anyone will have access to this repo
  • Please do not put sensitive data ( like passwords etc ) in this project 
  • If you need a private repo, you can use BitBucket
  • Go to GitHub ( ) and create a regular account
  • There is a very nice tutorial ( ) on how to set up a git repo on your local machine – so i am not repeating it here
  • If you face problems with SSH keys, then you can try using DSA instead of RSA
  • In Linux dont forget to do this in case SSH to GitHub is not working cd ~/.ssh; $ ssh-add id_rsa
  • There is a post on Stack overflow ( ) for SSH related problems
  • Once you install Git on your local system, you can also install a GUI like Smart Git
  • After copying all the public keys and stuff from your local system to GitHub, you can test to SSH to GitHub from your local system
  • GitHub dose not allow SSH access, but you can see if you are successful or not
  • Use the command ssh -vT 
  • The end of the message will say something like “Hi username! You’ve successfully authenticated, but GitHub does not provide shell access.”
  • If there is a problem, then you can see the verbose log of what SSH was trying to do and refer to Step 9
  • Use the “New Repository” button in you Dashboard to create a new repo ( Lets name it “test” and put the description as “test-repo”)
  • When you finish creating a new repo, GitHub will give you some nice instructions to follow on your local machine, follow them –
    Note – i have a directory called GIT on my desktop and all my projects are located there
Global setup:
 Set up git
  git config --global "Your Name"
  git config --global

Next steps:
  mkdir test
  cd test
  git init
  touch README
  git add README
  git commit -m 'first commit'
  git remote add origin
  git push -u origin master
  • Basically you are creating a README file and pushing it to GitHub ( my folder structure is /home/naveen/Desktop/GIT/test )
  • After these steps you should be able to see README in your GitHub account under repo “test” with the message “First Commit”
  • Now lets add another file to “test”
touch index.php
echo "<?php echo 'Hello World';" > index.php
git add index.php
git push -u origin master
  • You should now be able to see index.php in your GitHub account
  • Lets make some changes to index.php
echo "echo 'Hello World - 1';" >> index.php
git diff
  • git diff will show you the differences
git add index.php
git commit
  • When you use git commit instead of git commit -m ‘your message’ ,  a vim editor opens up by default and you can see what all changes have been done
  • You will have to type a commit message and exit
  • Type the message “added hello world 1” on the first line , then press escape , then press 😡 and hit enter – you will see the commit message
  • This is better way to see all files that have changed rather than just commit with a direct message
  • To change your editor from vim to nano use the command
git config --global core.editor "nano"
git push -u origin master
  • Changes should be  reflected on GitHub
  • To remove  an entire git repo, all you need to do is to delete the .git folder in your repository then you can do an init for a fresh start
  • Next how to clone an existing PUBLIC repository from Github
  • First we will delete our existing “test ” repo on our local machine, then we will clone the “test” repo on GitHub that we just created ( take care where you execute rm -rf and always keep a backup of your old git repos )
rm -rf .git
rm index.php
cd ..
rmdir test
git clone git://
  • You will now get back the test repo on GitHub – you can make modifications and repeat the cycle if necessary
  • To add some color to your command line interface use the below commands
git config --global color.status auto
git config --global color.branch auto
  • Change remote-origin with this command ( github does not allow git protocol – you might get an error while pushing )
git remote set-url origin
  • To show all files in a branch
git ls-tree -r branch
  • To compare the same file from 2 branches
git diff branch_1..branch_2 file.txt
  • To find if you need to pull updates from remote branch
git remote update
git status


  • You can create .gitignore file in your project or globally to ignore some files
  • For global gitignore, create a file somewhere. Eg /home/naveen/.gitignore
  • Now set the global settings with the below command –
git config --global core.excludesfile /path-to-gitignore-file


Good tutorials and references at

I will update the post as an when i learn more 🙂

Categories: GIT Tags:


No Comments Yet. Be the first?

Post a comment

Your email address will not be published. Required fields are marked *