Author: Romaan,
Last Updated: Dec. 23, 2016, 6:38 a.m.
Git is a distributed revision control developed by Linux Torvals in 2005 for Linux kernel development. It can be used for any programming environments to maintain versioning and allow developers to work in team and coordinate their coding efforts. Inorder to install git on debian based operating system, simply follow the below command:
sudo apt-get install git
Below is a quick cheat sheet that may be required while working with git:
Clone a remote repository
git clone <url>
Stage files
git add ... # Move the new or modified files to stage
git rm ... # Delete the file or mark the file as deleted to stage
git reset HEAD ... # Move the file from stage to unstage
git checkout # Discard any changes made to file
Commit files
git reset --hard # Discard all the staged and unstaged files
git reset HEAD~1 --soft # If unpushed, remove the previous commit and bring the changes to stage
git reset HEAD~1 --hard # If not pushed, remove the previous commit
git commit -m "Commit message" # Commit with a message
git commit -a -m "Commit message" # All all the tracking files to stage and commit
git commit --amend # Amend the recently modified files present in stage to previous commit
Branch management (A pointer to commit)
git checkout -b # Create a branch locally and switch to the new branch
git branch -a # List all the branches
git checkout # Switch to other branch
git branch -d # Delete the branch locally
git push origin :remote_branch # Remote the remote branch Updating
git pull # Does fetch and update
git fetch # Only fetches
Cherrypick
git cherry-pick # Take a commit from other branch and create another commit on the current branch
git revert # Creates a new commit by undoing the changes
Merge
git merge # Merge the branch_name to the current branch
Rebase
git rebase # Rebases and get the current branch on top of the branch_name
git rebase -h HEAD~n # n is number, helps rewrite the history
Comments: