Tutorial Two: Git terminologies
1. Config: 'git config' allows you to get or set any repository or global options. It allows you to set variables in the config file.
2. Init: 'git init' initializes your working directory to a git repository. It allows you to create a new repository or initialize an existing working repository.
3. Add: 'git add' adds all contents of a changed file to the index. 'Add' prepares the contents of the working tree by staging them for the next commit.
4. Diff: 'git diff' can be used to compare two working trees, commits, blob objects etc.
5. Status: 'git status' displays all the files and their statuses. it shows if a file is staged, which are changed and which are not staged.
6. Commit: 'git commit' records or updates changes to the repository. It commits the changes of your file against the author name, time, message and generates a SHA id for the commit.
7. Remote/Upstream: An online repository hosted on a server where everyone working on the repository commits to. Local changes can be synced to the online repository at your own will. In git it's aliased to origin.
8. Branch: A 'branch' is an extension of the original repository. For instance, if master is the main upstream /remote repository, then you can create a branch feature which consists of the master repository copy as well as your additional changes. You can push the local repository changes to the feature branch in the remote to avoid disruption of the master repository. You could merge your branch back with the master to sync it with your latest changes.
9. Working copy/tree: The working tree/copy is the current copy of the local repository you are working on. If you checkout a branch the working tree changes accordingly so that you have the changes of that particular branch alone.
10. Pull: 'Pull' refers to syncing your local repository/working tree with the new changes in the remote. Your local repository/working tree gets updated with the changes made by other users who are committing to the remote.
11. Push: 'Push' is the reverse of 'Pull'. It refers to syncing you remote with the new changes of your local repository. Others can take a pull to stay in sync with your changes.
12. Clone: Cloning is nothing but making/downloading a copy of the remote repository. For instance, if you start working on a repository for the first time you clone the remote repository in your local machine which then becomes your local repository. It can be synced with your remote repository as and when you are online.
13. Checkout: This command is very useful when you are working on more than one branch and you require to switch between branches. 'Checkout' allows you to create a branch and also switch between two branches.
14. Merge: 'Merge' gets the changes from the remote and applies it to your local. If there are no merge conflicts the changes are committed immediately to your working copy. Mostly, used to merge two branches.
15: Fetch: 'Fetch' refers to syncing you local with the remote except that it allows you to compare the differences and then merge. 'Fetch' gives you more control. Mostly used to get changes from the remote without conflicts.
16: Stash: When you are working on a local repository and need to run any command that might alter your working copy, git restrains you from losing the uncommitted changes. The uncommitted changes can be moved to a temporary stack so that the working copy is clean. 'Stash' refers to saving your working copy changes before you apply any other changes over the working copy of the current branch. 'Pop' would help retrieve the stashed changes.
17: Log: 'git log' gives a bird's eye view of all the recent commits made to the branch. It gives a detailed information of what time the commit was made, author, commit message, SHA id etc. It allows you to analyse the status of your working tree. This could be particularly helpful if you want to move to a particular commit.
18: HEAD: A symbolic name referring to the latest commit of the current branch.
19. Tag: A tag is used to mark an important point in the repository. For instance, version one changes can be tagged as git tag -a v.1.0 when you begin your work on version 2. Tag allows you to come back to the same point if need arises.
20. Rebase: A 'rebase' applies changes from a different branch or remote on top of the changes in the working tree. It keeps the uncommitted working copy changes and also with your latest changes from other branch or remote.
21. Reset: This is one of the most important commands which comes to your rescue if something goes wrong. A 'git reset' can be used when you need to:
1. Unstage a file staged unwillingly before committing.
2. Undo a recent commit by moving the HEAD to the previous or a specified commit using the SHA id. One can roll back a commit using git reset HEAD.
There are two types of reset:
1. Soft: Allows to undo a commit but puts the file back in the staging area. So indexes are not lost.
2. Hard: A dangerous option that allows you to undo a commit but any uncommitted working copy changes will be lost. Commit and indexes are completely removed and the new index is set to the previous or a specified commit.
22. Remove: Remove is similar to a 'git reset soft' except that it removes the file itself from the staging area as well as the working directory.