Monday, August 27, 2012

GitHub for Dummies - From Command Line

GitHub is a free cloud based version control system. Its extremely powerful but at the same time is a little daunting to use for the first time.
Here is a small guide to easily use GitHub without much fuss! 
Step 1: Create an account on GitHub  (https://github.com/)
  If you are ok with your code being public then GitHub is free to use else it will cost you. 
  
Step 2:  Create a new repo or repository on GitHub. Name it test.
Step 3: Download GIT tools from the site and install. 
Step 4: In your working directory which you want to push to git do the following: 
git init  (initializes your local directory to be a git compliant directory)
git add *  (adds all files in current directory and sub directories to git local repo)
git commit -m "Initial Commit" (Commits all added files to local repo first)
git remote add origin https://github.com/USERNAME/REPONAME.git (add a remote git reference for github repo)
  Alternatively you can add
git remote add origin git@github.com:USERNAME/REPONAME.git
git push -u origin master (Push all the committed files which will be in master repo by default into the remote site you added called origin)
That's it done. Go online and see your code in all its glory!

After this for incremental updates just do this:
git add *
git commit -m "Updates"
git push -u origin master (This will add whatever was changed).

You can see what will be committed using git status command.