GIT – Developed by Linus Torvalds
Source code management tool
Git is a Distributed Version control system
Q. What are the types of Version Control Systems?
- Central Version Control System
- Distributed Version Control System
Working directory is nothing but a Folder where Source Code is stored.
To convert folder to working directory,$ Git init
To configure user and email to git,$ git config user.name "Machindra"
$ git config user.email "user@gmail.com"
To configure globally user and email to git,$ git config --global user.name "Machindra"
$ git config --global user.email "user@gmail"
There are 3 types of files in git,
1. Untracked files – by default file status is untracked
2. Staged files – Before commit
3. Committed files – After Commit
To check status of files in git,$ Git status
To add 1 file to staging,$ git add fileName
To add all files to staging,$ git add .
To remove files from staging to untracked,$ git rm --cached fileName
To Commit staged files,$ git commit -m "My commit message"
To see list of commits,$ git log
To check commits in one line,$ git log --oneline
To create new branch,$ git branch branchname
To check list of branches,$ git branch
To change the working branch,$ git checkout branchName
To merge branch with master branch, – to merge any branch you’ll be in master branch first$ git merge branchName
REBASE => is fast forward of merge
To rebase you’ll be on respected branch$ git rebase master
Then go to Master Branch,$ git checkout master
Then merge that branch to master branch,$ git merge branchName
To rearrange the commit order/place
We can’t change order/place of First/head Commit
$ git rebase -i HEAD~(remaining_commits)
Ex. $ git rebase -i HEAD~4
[where n=total commits, n-1=4 ]
After this command you’ll be in one file, where you can change the order of commits
MERGING COMMITS :
We can’t remove first commit
$ git rebase Head~4
Replace the word pick with squash in file , i=insert and save the rebase file
$ git log --oneline
To merge selected commits with master branch, got to master branch and then hit command,$ git cherry-pick commit-id commit-id
Ex. $ git cherry-pick d6ertc f45gtr4
git stash ( keeping something secret or hidden – if some work is unfinished we can keep that files hidden from user, so git cannot access it)
To stash the stagged files$ git stash
To stash staged & untracked files$ git stash -u
To see the list of stashes$ git stash list
To get back the stashed files$ git stash pop
To bring the older stash out$ git stash pop stash@{stash_number}
Git Ammend – meaning to override
To ammend one commit to another commit, if we have made a small change in file and we don’t have to create new commit then,$ git commit --amend -m "commitName in which i want to amend this commit"