Skip to content

Instantly share code, notes, and snippets.

@sahajamit
Last active March 18, 2016 01:54
Show Gist options
  • Save sahajamit/9c933014efcc1bcd461e to your computer and use it in GitHub Desktop.
Save sahajamit/9c933014efcc1bcd461e to your computer and use it in GitHub Desktop.
For Cloning:
git clone -b <Branch_Name>
To create and checkout
git checkout -b <Branch Name>
git branch <Branch Name>
git checkout <Branch Name>
git diff --cached
or
git diff --staged
You can undo git add before commit with
git reset HEAD <file>
You can use git reset without any file name to undo all due changes
For Merging two branches
http://stackoverflow.com/questions/14168677/merge-development-branch-with-master
I generally like to merge master into the development first so that if there are any conflicts, I can resolve in the development branch itself and my master remains clean.
(on branch development)$ git merge master
(resolve any merge conflicts if there are any)
git checkout master
git merge development (there won't be any conflicts now)
There isn't much of a difference in the two approaches, but I have noticed sometimes that I don't want to merge the branch into master yet, after merging them, or that there is still more work to be done before these can be merged, so I tend to leave master untouched until final stuff.
To See Local and Remote branches:
The easiest way is just to use the git branch commands’ various options. -a shows all local and remote branches, while -r shows only remote branches.
git branch -a
git branch -r
To see the remote repository url:
git config --get remote.origin.url
Rebasing
$ git checkout experiment
$ git rebase master
It works by going to the common ancestor of the two branches (the one you’re on and the one you’re rebasing onto), getting the diff introduced by each commit of the branch you’re on, saving those diffs to temporary files, resetting the current branch to the same commit as the branch you are rebasing onto, and finally applying each change in turn.
GIT
git checkout -b LocalName origin/remotebranchname
https://help.github.com/articles/remove-sensitive-data/
git push origin --delete <branchName>
https://git-scm.com/book/en/v2/Git-Tools-Submodules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment