My Git Cheat Sheet
git branch
git branch -vv
git branch <new-branch-name>
git checkout -b <new-branch-name>
git checkout -b <desired_branch_name> origin/<remote_branch_name>
git checkout -b additional_commands origin/additional_commands
git checkout <Branch Name>
git clone https://github.com/rohitraja/git-cheat-sheet.git
If you wish to have your same code hosted in multiple remote repositories eg. one on Github and one in Heroku refer these link for more help Github1 Github2
$ git remote add origin <URL>
# Sets the new remote
$ git remote -v
# Verifies the new remote URL
# Eg
heroku https://git.heroku.com/whispering-caverns-58054.git (fetch)
heroku https://git.heroku.com/whispering-caverns-58054.git (push)
origin https://github.com/rohitraja/emaily-udemy.git (fetch)
origin https://github.com/rohitraja/emaily-udemy.git (push)
$ git push heroku master
# to push it to heroku
$ git push origin master
# to push to Github
git log --oneline --graph
git log --oneline --decorate
git checkout <commit Id>
git commit --amend
Reffer Link
$ git config user.name "Rohit Pahan"
$ git config user.email "rohit.pahan@org.com"
$ git commit --amend --author="Rohit Pahan <rohit.pahan@org.com>"
git fetch
git pull
git remote -v
Set your local branch to upstream where the push should go -> : if the branch is created local you need to upstream
git push --set-upstream origin <branch name>
git diff <souce> <destination>
git cherry-pick -n <commit> # get your patch, but don't commit (-n = --no-commit)
git checkout <target>
git merge <source>
git merge --abort
git checkout <path-to-file> :
Find out, if we have branch A and it has 10 commits, we want to cherry pick and merge commit#1,4,7 to branch B
git config --global --add diff.guitool kdiff3
git config --global --add difftool.kdiff3.path "C:\Program Files\KDiff3\kdiff3.exe"
git config --global --add difftool.kdiff3.trustExitCode false
git config --global --add diff.tool kdiff3
git stash save "Save_Name"
git stash apply stash@{index} //will apply the stash and also kep the stash
git stash pop stash@{index} //will apply the stash and pop it from stash list
git stash drop stash@{n} //Delete specific stash
git revert c6f37fd
git reset --hard HEAD
git reset --hard 00b9c34
git reset --soft HEAD~1
Undo commit and redo ## reffer stackoverflow
$ git commit -m "Something terribly misguided" # (1)
$ git reset HEAD~ # (2)
<< edit files as necessary >> # (3)
$ git add ... # (4)
$ git commit -c ORIG_HEAD
git rm --cached -r <Folder Name>
git rm --cached -r public_html/GrosumCordova/plugins
git config --add remote.origin.proxy "" //bypass Proxy
git config --global --get http.proxy // check Proxy
git reflog
git difftool --tool kdiff3
git push --set-upstream origin b1
Eg: To include private repositoy in Node project in package.json file
"dependencies": {
"repo1": "<protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish> | #semver:<semver>]",
"repo2": "git+https://user123:password123@github.com/abc/xyz.git#master"
}
Note: If you have "@" in you password you may face issues.