Learning Git

Now-a-days if you search for any source code, this word is always there. "GIT". What is so special about it?

Well check out the Wikipedia page to know about its history. I would like to borrow one sentence from Wikipedia though:
Git was initially designed and developed by Linus Torvalds for Linux kernel development in 2005
The light bulbs glowed for the first time. I always fancied Linux and its kernel development, though I knew nothing about it. But this was the first time something near to the Linux kernel was available to me, and which could help me manage my source code. Although the learning was mandated for official reasons, I now fancy Git in "all and everything" which I code.

Having said that what is the starting point? I implemented Git in my local development first. My aim was to have Git take backup of everything in my development folder. The starting point was this Git book.

I summarize the tasks I was upto:

  1. Create a fresh project folder
  2. Copy all my required and necessary folders and files
  3. Back them up to a shared folder (server)
  4. Work independently of my local machine

Step 1: Create a fresh project

The command line is your friend in case you are learning any Linux related/open source related projects. Git is no different. I created a folder myproject in projects folder. Then issued the Git initialize command after navigating to the myproject folder in prompt.

C:\projects\myproject> git init

Git creates a folder and two files.

  • .git folder
  • .gitattributes file
  • .gitignore file
Unlike Miscrosoft Visual Source Safe (VSS), it does not create files within your project sub folders. This is extremely helpful in most cases. If you choose not to use Git anymore, just delete the three objects mentioned above, and you are free to import into any other version control software. (But it won't be necessary).

Step 2: Copy project folders and files

My next step was to copy just the required files and folders from existing project folder. Even though I could have initiated in my existing working folder with git init, I chose to create a different folder. This was to make sure I didn't screw up my files just in case I ran some unexpected commands.

Once I have added folders and files, I have to add the files to git repository.

git add . (for all files, or add by each file)

git status

The above command will list me the changes from first commit, and up to now. 

git commit

The above command will update my changes to git repository.

Step 3: Back up to server (shared folder)

This is where I was stuck for a lot of time. Thankfully I got guidance from ElegantCode website. I followed the information presented in that and I was able to push my changes to shared folder. I have created a folder myproject in server as well.

C:\projects\myproject> pushd \\remoteserverip\anantha\projects

y:\projects> mkdir myproject

y:\projects> cd myproject

y:\myproject> git init --bare

y:\myproject> popd

C:\projects\myproject> git remote add origin //remoteserverip/anantha/projects/myproject

C:\projects\myproject> git push origin master

Step 4: Work independently of local machine

I can now create a folder anywhere in my LAN and can point to this server and git pull the changes. This is a starters guide for git.


No comments :

Post a Comment