git_cheat_sheet
This is an old revision of the document!
Table of Contents
Git Cheat Sheet
Resources
Install
Run the following to create the user config file:
git config --global user.name "Stephen Heise"
Run the following to find where the .gitconfig file is:
git config --list --show-origin
Replace it with this:
[core] editor = 'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin [user] name = Stephen Heise email = Stephen@tallguyracing.com [mergetool] prompt = false keepBackup = false keepTemporaries = false [merge] tool = winmerge [mergetool "winmerge"] name = WinMerge trustExitCode = true cmd = "/c/Program\\ Files\\ \\(x86\\)/WinMerge/WinMergeU.exe" -u -e -dl \"Local\" -dr \"Remote\" $LOCAL $REMOTE $MERGED [diff] tool = winmerge [difftool "winmerge"] name = WinMerge trustExitCode = true cmd = "/c/Program\\ Files\\ \\(x86\\)/WinMerge/WinMergeU.exe" -u -e $LOCAL $REMOTE [alias] st = status ci = commit -m br = branch ba = branch -a co = checkout di = diff dt = difftool fa = fetch -a md = merge origin/develop cd = checkout develop pp = !git pull && git push [winUpdater] recentlySeenVersion = 2.15.1.windows.2 [remote "origin"] prune = true
Try Git
| git init | |
| git config --global core.editor "atom --wait" | Make Atom the default editor. |
| git config --global user.name "Stephen Heise" | |
| git config --global user.email "Stephen@tallguyracing.com" | |
| git status | |
| git add filename.txt | |
| git commit -m “Commit message” | |
| git log | |
| git remote add origin https://whatever.com | |
| git push -u origin master | -u means remember these settings |
| git pull origin master | |
| git diff head | |
| git diff --staged | |
| git reset octofamily/octodog.txt | unstages a file |
| git checkout -- octocat.txt | go back to last checkout / undo |
| git reset --hard origin/master | Throw away all local commits. |
| git branch -a | Show local and remote branches. |
| git branch clean_up | Create new branch. |
| git checkout clean_up | Switch branches. |
| git checkout -b new_branch | Checkout and create branch at the same time. |
| git checkout filename.txt | Undo local (unstaged) modification. |
| git rm '*.txt' | Remove local files and include the removal in the staging area. |
| git rm -r folder_of_cats | Recursively remove all folders and files from the given directory. |
| git commit -a | Include the deletion of local files to staging area, do the commit. |
| git merge clean_up | |
| git push origin --delete <branch_name> | Delete a remote branch. |
| git branch -d <branch name> | Delete a branch. |
| git branch -D <branch name> | Force delete a branch. Use if branch not merged. |
| git remote prune origin | Clean up remote branch list. |
| git push | |
| gitk | A commit viewer. |
| git tag -a tagname -m “commit comment” | Annotated tag (preferred over lightweight tags). |
| git tag tagname | Lightweight tag (good for temporary tags). |
| Start new branch | |
| git checkout -b branch-name | Create new branch and checkout. Unstaged changes are retained. |
| git push --set-upstream origin branch-name | Push and create branch on remote. |
| Get new remote branch | |
| git pull | Make sure git knows about the remote branch. |
| git checkout --track origin/branch_name | Grab the remote branch. |
| Merge branch | |
| git checkout master | |
| git merge branch-name | |
| Delete branch | |
| git push origin --delete branch-name | Delete the remote branch. |
| git branch -d branch-name | Delete the local branch. |
| Undo last commit | |
| git reset HEAD~ | Reverts last commit, but does not change files. Only do if commit is not pushed. |
| git reset --hard HEAD~1 | Reverts last commit and reverts changed files. Only do if commit is not pushed. |
| Reset tag position | |
| git co develop | Get on the correct branch. |
| git ls-remote --tags | List remote tags. |
| git push --delete origin tagname | Delete the remote tag. |
| git tag -d tagname | Delete the local tag. |
| git tag tagname | Create the local tag. |
| git push origin tagname | Create the remote tag. |
| git ls-remote --tags | Check you got it right. |
Visual Studio Online
git remote add origin https://tallguy789.visualstudio.com/_git/AnotherTestProject git push -u origin --all
Import from SVN
git svn clone https://ares/svn/SVNRepository/Presentations --no-metadata --tags=Tags --trunk=Trunk --branches=Branches --authors-file=..\users.txt
git_cheat_sheet.1519875137.txt.gz · Last modified: 2018/03/02 04:32 (external edit)
