Contains all basic GIT commands with usage examples.
GIT - Version Control
git init
- To initialize a repository with git.
git status
- to get info on untracked files.
git add
- to add sigle file to tracking logic.
- to add all files to tracking logic.
git commit
- to add currently tracked files to version of the code that we wanna save.
- “-m” : to give our commit a name
git log
- to get info on previous commits
- last commit is the HEAD in our branch
- press UP/DOWN to see all.
- press “q” to quit.
git checkout
- to go to a previous version of our code.
- get “_commit_id” from “git log”
- to get back to lastest version.
- revert/delete all unstaged changes.
git reset
- to delete previous commit(s).
- get the ID of the commit just before the commit you wanna delete.
- all the commits after that commit will be deleted.
git branch
- to get name of current working branch
- adding a new branch
- any commits to new branch stays in that branch only.
- merging two branches (after commiting in new branch)
- deleting the new branch (like after merging)
- Merging when two branches have different changes at same place.
- This is called a conflict.
- You can keep current commit, keep incoming (from the other branch), or keep both.
git remote
- to establish a connection between our local and remote repository.
- to remove remote repo
git push
- to upload code from our local to remote repository.
- “U” establishes an upstream for our connectoin.
git pull
- to get changes made in the remote repo.
git stash
- to save your current code as draft and jump to last commit.
- use stash in this case instead of using commit.
- to apply last draft to current branch
- to view all drafts
- to apply a particular draft to our current branch.
- to save a description with the stash (for easy navigation)
- to delete a stash
- to apply stash to current branch and delete it from stash list
- delete all stashes
git merge
- Suppose we have 2 branches “one” and “two”
- “one” has commits o1,o2
- “two” has commits t1,t2,t3
- we wanna merge t3 with o2
- such that “one” now has o1,o2,t3(having t2,t1 merged within) commits
- so we’ll use squash here.
git squash
- to merge all the commits of the current branch in 1 last commit.
git rebase
- Suppose we have 2 branches “one” and “two”
- “one” has commits o1,o2,o3,o4
- “two” has commits t1,t2,t3
- we wanna get o4 as the base of two
- such that “two” now has o4,t1,t2,t3 commits