Hi !! Today I am going to explain GIT briefly.
At the heart of GitHub is an open source version control system (VCS) called Git.
Git is responsible for everything GitHub-related that happens locally on your system.
The pictorial representation of the GIT work-flow.
Major GIT commands:
git init : Initializes a git repository – creates the initial ‘.git’ directory in a new or in an existing project.
git clone : Makes a Git repository copy from a remote source. Also adds the original location as a remote so you can fetch from it again and push to it if you have permissions.
git checkout : Checks out a different branch – switches branches by updating the index, working tree, and HEAD to reflect the chosen branch.
Example: git checkout newbranch
git add : Adds untracked files to working directory.
Example: git add file_name
git rm : Remove file from working directory so that they will not be tracked.
Example: git rm -r file_name
git commit : Takes all of the changes written in the index.
Example: git commit -am “commit_message”
git log : At any point you can view the history of your changes.
Example: commit 83df8b1676549c85c89afdf8fb1bf47ec48333dd
Author: Shubhala Singh <email@example.com>
Date: Tue Dec 6 15:07:06 2016 +0530
git status : Shows you the status of files in the index versus the working directory.
It will list out files that are untracked (only in your working directory), modified (tracked but not yet updated in your index), and staged (added to your index and ready for committing)
git status -s : display short status.
Each file in your working directory can be in one of two states:
Tracked – Files that can be unmodified, modified, or staged.
Untracked – Files which Git sees but you didn’t have in previous commit.
CONTRIBUTING.md – Files that is tracked and has been modified in working directory but not yet staged. Whereas .md is markdown.
README.md is prefered over README as it give HTML summary.
Now coming back to GIT command.
git stash : Temporarily saves changes that you don’t want to commit immediately.
git branch : Lists existing branches
git remote : Shows all the remote versions of your repository.
Example: git remote
git pull : Fetches the files from the remote repository and merges it with your local one.
Example: git pull origin branch name
git push : Pushes all the modified local objects to the remote repository and advances its branches. Example: git push origin master
git cat .gitignore : display ignored files.
git diff : Show changes between commits, commit and working tree, etc. By using this command we can see what had changed but not yet staged.
git show : Shows information about a git object
git merge : Merges one or more branches into your current branch and automatically creates a new commit if there are no conflicts. Example: git merge newbranchversion