22 July 2017
Git is a version control system for tracking changes in computer files and coordinating work on those files among multiple people. This post is a collection of important Git command Cheat Sheet that i use in my day to day basis. For details please refer the official git page.
#Add global User Name ~$git config --global user.name "<User Name>" Example :~$git config --global user.name "Nitendra Gautam" #Add global Email Address ~$git config --global user.email "<Email>" Example :~$git config --global user.email "[email protected]"
(1) Create a branch in git locally if it does not exist ~$git checkout -b <Git Branch Name> Eg :~$git checkout-b develop Switched to a new branch 'develop' (2) Push the local branch(origin) to UpStream to origin $git push --set-upstream origin develop Total 0 (delta 0), reused 0 (delta 0) To https://github.com/nitendragautam/nitendragautam.github.io.git * [new branch] develop -> develop Branch develop set up to track remote branch develop from origin. #verify that you are in develop branch ~$git branch * develop master
~$cd <Local Repository Folder> Eg :$cd testRepo #List all the remote Branches and shows which branch you are current at with * sign ~$git branch -a #Switch to remote branch which you want to work ~$git checkout <branch name> #verify the branch that you changed /Sanity check for the branch which you are working on ~$git branch
If you have new project or serveral projects that you want to add under several repo ,you need to add it first .
This needs to be done so that Git can recognize the submodules or project folder added.
~$git add <File Name> ~git add JavaProject
#### Pulling down remote repository in Git
~$git clone <git-repo.git>
#### Deleting the file from the repository
~$git rm file.name #If you don’t want to add the file to the repository , don’t stage it or you can alos delete it from the file system
git checkout master git merge develop git push -u origin master
Rebase Rebase is recreating your work of one branch onto another. For every commit that you have on the feature branch and not in master, new commit will be created on top of the master. Read this again, slowly: new commit for every old one, with the same changes.
Merge Merge is a new commit. It is a simple commit with one difference – it has two parents. All other regular commits have only one.