Git in Nutshell

Git is kind of version control system (VCS) which would keep track every lines of your code so that you can recall specific versions later. Using a VCS also generally means that if you screw things up or lose files, you can easily recover.

First thing first, let’s get your git :

Make sure your git can be recognized by doing

git –version
git version 2.7.4 (Apple Git-66)

Next you need to create a directory where git will keep its eye on your files, it’s called as repository.

To create repository, you may create it from scratch or you also can clone from another repository. For first option, let’s create new directory that will contain your files, get inside it, and execute git init This command will create a git repository without any name.

Or for second option, you can start clone other repository simply by doing git clone /path/to/repository or git clone username@host:/path/to/repository

for example, you found out interesting code here at https://github.com/felixsu/CleanAndroidCookbook and want to add/change that existing code, then simply by doing git clone https://github.com/felixsu/CleanAndroidCookbook.git and that repository will be cloned into a new repository in your local.
*Please remember that your repository is still in your local, to make it available in remote, you need to push it manually

After repository is setup, now you’re ready to change or adding some files inside it. Basically your local repository consists of three “trees” maintained by git. the first one is your Working Directory which holds the actual files. the second one is the Index which acts as a staging area and finally theHEAD which points to the last commit you’ve made.

git-trees

After files inside repository was manipulated, you may check the repository status by doing git status. It will show you list of files that haven’t been staged for commit. To stage files, simply do git add -A to add all changed files or do it one by one by doing git add filename. If you execute git status, it will show that some or all files is staged for commit. To do commit, execute git commit -m "your message, include the quotes".

Horray, you already commit your change and now the changes are stored in repository database. Next is push it into remote. To do it, first you must mention your remote to your repository. You can do it by git add remote origin https://github.com/... then push it using git push origin branch_name.

That was basic flow to works using git. There still many more to be described such as gitignore file, merge action, revert action, pull action, branch action, cherry pick, stash. They would be necessary when you’re really works using git, but for welcome speech, this post should be cover all the basic thing in git. Happy coding! 🙂

reference : http://rogerdudler.github.io/git-guide/


Comments

Leave a Reply

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