Git is a version control system designed to handle everything from small and large projects with speed and efficiency.
It is free and open source distribution.
Git is very easy to learn. It has a very small footprint and lightning fast performance.
It outclasses other tools like Subversion, CVS with cheap local branching and multiple workflows.
Git is very useful in the following cases
Accidental deletion of the code, git can help to get back your code.
Accidental modification of the code or broke something, it helps you to revert it.
It lets you share and exchange your code with other developers very easily.
Need to know what recent changes you made to source code, git is a friend to you.
It lets you back up your source code to a remote server.
The installation process of git
Run following command inside the application folder, it will create .git folder inside the application.
Now you can start tracking version of your application.
Clones repo from GitHub
Clones repo with folder name mylib
Shows status means untracked, modified and deleted files and the current branch
s for short, display short descriptions
For ignoring files to be added in Git. Create .gitignore file
Add files and paths of files
To remove file from stag and working directory
If file is modified, then staged. and you want to remove
f for force removal
Renaming file in git.
This is similar to following commands
Give URL of the online repo, an origin is a nickname, u can give any name
To confirm above commands
Add particular file to git attention, create snapshots
Add two files or more
All files ends with c
Add all files
Commit by adding message (create checks points)
Create new branch and move to it.
To create branch
To navigate another branchname
Create new branch with second last commit of master branch
Display Commits history recents two commits.
Recents two commits with modifications in those files
Recents two commands with files names and number of lines modified
Recents two commits in one lines
More options in --pretty
Option Description of Output
%H Commit hash
%h Abbreviated commit hash
%T Tree hash
%t Abbreviated tree hash
%P Parent hashes
%p Abbreviated parent hashes
%an Author name
%ae Author email
%ad Author-date (format respects the --date=option)
%ar Author-date, relative
%cn Committer name
%ce Committer email
%cd Committer date
%cr Committer date, relative
Shows nice ASCII graph
Limit log output
in weeks, months, years, days
Shows commits of remote branch which are not in local branch
cherry pick - add commits from one branch to another.
Move to branch where you add the commit
Add more cherry picks in one go
If cherry picks get halted, then resolve the conflicts, run your code
then run continue command and add more cherry picks. --continue adds modified files
For any resolved conflicts.
After that successful cherry picks
Abort cherry pick in middle of process
To cherry pick merge instead of commit
and push the changes
If you have committed, and forgot to add few files and want to make same commit.
List all branches with current branch
List all branches with current branch and last commits
List all remote branches
To see all remote and local branches and which are out of date
List all branches which are merged to current branch
List all branches which are not merged to current branch
To delete allready merged branch
To delete un-merged branch and lose their work.
Identifies possible whitespace errors
To see the difference between last commit and unstaged data (before add)
To see the difference between the last commit and staged data (after add)
Show modified contents in the specific file before the stage.
Undo changes or modification before stage(add)
In particular file
For all changes in all files
Undo changes or modification after stage(add) means unstage(un-add)
in particular file
For all changes in all files
Undo last commit and all changes, HEAD^ -> second last commit
Apply in between merge and undo the merge
If merge commits created and to undo merge. Here ORIG_HEAD stores previous head
Head stores merge commit.