Git Hands On Workshop

A friend requested to do a small hands on workshop on git. I prepared the following very brief introduction and tutorial  for him and his team.

What is Git?
Git is a distributed revision control and source code management (SCM) system with an emphasis on speed. Git was initially designed and developed by Linus Torvalds for Linux kernel development in 2005.
 
What are forks?

When you are cloning a git repo on your local workstation, you cannot contribute back to the upstream repo unless you are explicitly declared as contributor.

So that clone (to your local workstation) isn’t a fork. It is just a clone.

Basic Git Operations
To initialize an existing project in Git, go to that directory and type this command.
In order to work with code, you will get a copy of it. The path to clone could be copied from bitbucket / github etc shown at top e.g. git clone https://github.com/mrkkhattak/mysql-scripts.git

Once you have made changes to the code, before committing doing git status will show a list of modified files for analysis.

If there are any files, you don’t want to include in your project on git create a file named .gitignore with names of those files e.g. out put of a .gitignore file:

In git you have to add files / folders which are not yet part of project before you could commit them. To add an individual file git add filename (this concept is also called staging in git)

To add all modified and deleted files in your project, run this command:

This records a snapshot of your changes. With every commit it is recommended to include a comment so in future it could be easily tracked and know what changes were done and why. 

The commits don’t push the changes immediately to the remote repository. To push them to remote repository, use this command:

To see the differences between between your changes (not yet committed or pushed) and your last changes already committed run this command:

To remove a file in git first you remove the file from local, then run the following command, which will communicate this change to staging. In next commit, it will remove this file completely from repository as well.

To rename a file, use this command. 

By default, with no arguments, git log lists the commits made in that repository in reverse chronological order. There is a comprehensive list of options available to utilize with this git log command to make it more useful. Some common scenarios are comparison of history word by word, line by line etc.

If changes have been pushed to your fork by other users, you will need to pull them in before you can push. This pulls those changes in and applies your changes on top of them.

Above I have listed only a few common scenarios / commands, while git provides many more options and it will take time to master them all.

There are many resources available which would help in learning and exploring git further. Following are the two links which I found pretty useful:

http://git-scm.com/book/en/Getting-Started-Git-Basics

https://github.com/AlexZeitler/gitcheatsheet

Linux Training Workshop

In last few months, I conducted Linux Training Workshop for my colleagues in groups. It was aimed at our developers who were developing LAMP projects on Windows machines.

The presentation gives a very basic summary but in workshop I provided them examples and later also distributed a document which contains useful Linux commands.