Sunday, January 13, 2013

getting started with GIT - an introduction


Git is an open source distributed version control system.



The screen shots were taken from youtube presentation by Scott Chacon.



Traditional version control systems used to have a single storage where all the developers used to connect and operate. This lead to a single point of failure.



In git, there is no single server which maintains the history. All parties/developers's machine become node in the distributed system and they can work in isolated fashion as well. Basically the system behaves as loosely coupled.



Below is the comparison between traditional VCS and Git. Git stores the file contents along with the checksum which relieves it from managing the change log and plenty of indirected connections between file versions.


Git stores all the checksum as directed graph which helps it easily identify what and how to merge code.



Below are the basic commands for doing any file modifications:



when we do 'git checkout' it creates index database and then creates a local directory where stores all the contents. Running 'git add' puts the file contents along with the checksum in the Index database. The final 'git commit' does a commit from Index database to local repository. Note that 'commit' doesn't look at the local files, it only looks at Index database for final commit to repository. What it means is after doing 'add', we can delete the local file however 'commit' will still continue without loosing the change.



Merging: git does merging by looking at the changes between current branch 'master' and the branch to be merged 'branchA'. It basically walks through the directed graph and tries to find the common ancestor. If found then it does a fast-forward merge which means it moves the head pointer to 'branchA'.


Simple merge (fast forward). merge of branch iss53:






Simple delete: if Head can reach the branch directly then it deletes else skips. so it has a safety mechanism.


git branch -d iss53



i18n can't be reached from head so using below command forcefully deletes it. Hard delete.


git branch -D i18n



steps of code push.


scott pushes the change



git does a fast-forward merge in origin master repo because it sees a common ancestor between origin master and scott's master.



Now Nick tries to push but that will fail as origin master in Nic's local repo and in origin remote repo are pointing to different commit versions.


so Nick does a 'git fetch' first.



then he does merge. because (pull = fetch + merge).



now things look good and origin master points to right commit version. and hence the collaborated delivery completed gracefully,



How to create Aliases?



Git subsets




answer is: git log i18n ^master



What is the change in iss53 which is not in i18n?



answer is the highlighted commit histories:





...Quizes...


Git Incoming? its the change which is in origin/master and not in local master. solution: fetch will pull in the change.


here is how to check what changes we are missing in local:


git log origin/master ^master


Git outgoing? its the change which is in local master and still not got pushed to origin/master. solution: git push will deliver the change


here is how to check what changes we still did not merge to origin/master from local:


git log master ^origin/master

No comments:

Post a Comment