CategorySource Control

git Cheat Sheet

Command line tools

Download git command line tools for Windows:

Command line tips

Create a branch and switch to it

git checkout -b branchname 

Switch branches

git checkout branchname

Push to remote repo

git push origin branchname 

Merging branches

Be sure to commit and push branch to remote repo first for completeness
git checkout master
git merge branchname

Delete local branch

git branch -d branchname

Delete remote branch

git push origin :branchname  (watch for the colon)

Undo a branch merge

git reset --hard SHA1__Commit_Prior_to_Merge

Sync all remote branches

git remote update
git fetch --all
git pull --all
If that fails, do it one-by-one manually:
git checkout -b <local branch> <remote>/<remote branch>

Saving Credentials

git config credential.helper store

Cloning a Remote Git Repo

git clone <remote_git_url>

Cloning from SVN with Commit History

git svn clone <svn-url>
git remote add origin <remote_git_url>
git push origin master
Remember to add a .gitignore file

Reverting the current repo back to a previous commit

git reset --hard <commit-id>
(reset without –hard only resets the history. –hard also resets the files)

Reverting a single file from a known specific commit

git checkout <commit-id> <file-path-to-restore>

Reverting a specified single file or all files in the path back to the last commit

git checkout -- full-file-path-to-restore>
git checkout -- full-path-to-folder-restore>
To revert ALL uncommitted changes:
git checkout -- . CheatSheet


See also:

Accessing a Remote Git Repo from behind a Proxy Server

It is quite tricky accessing a remote Git Repo when you are stuck behind a corporate HTTP Proxy Firewall. The proxy requires authentication to access the outside world.

Here is how to specify the proxy server settings for Git to negotiate its way out to the remote repo using Windows Authentication:

Git Proxy Server Configuration

git config --global http.proxy http://DOMAIN\\USERNAME:PASSWORD@PROXY_ADDRESS:PROXY_PORT

Handy .gitignore file for Visual Studio on GitHub

git doesn’t exactly play nicely with Visual Studio (or maybe it’s the other way around).  It probably doesn’t matter who’s fault it is. Fact is, if you add a Visual Studio solution to a git repo, you are bound to end up with a tonne of files you don’t really want in there. Cache files, build files, and all the other VS bloat.

So I went searching for a “prepacked” .gitignore file so I didn’t have to guess all of the file types myself.  So I Googled and got this page on GitHub.

Many thanks to the 240+ contributors to-date for compiling this great resource.



© 2018

Theme by Anders NorénUp ↑