This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| cheatsheet:git [2023/02/14 10:48] – kamaradski | cheatsheet:git [2023/07/24 08:46] (current) – [other common commands] kamaradski | ||
|---|---|---|---|
| Line 46: | Line 46: | ||
| </ | </ | ||
| - | ===== other common commands ===== | ||
| - | git init: Initialize a new Git repository. | + | ===== Use git stash to move code between branches ===== |
| - | git clone < | + | A common use case that I use git stash for is when I make changes in the wrong branch that are bigger than just a few lines and thus not so easy to copy/paste into the next branch. |
| - | git add < | + | Here is how I do it: |
| - | git reset <file_or_directory>: Unstage | + | <code> |
| + | git stash // stash your changes | ||
| + | git checkout feature_branch // Navigate | ||
| + | git stash apply // apply the stashed changes | ||
| + | git add . | ||
| + | git commit -m "Your commit message here" | ||
| + | git stash drop // delete the stash in case yuo no longer need it | ||
| + | </ | ||
| - | git commit -m "< | ||
| - | git log: Display the commit history of the repository. | + | ===== other common commands ===== |
| + | |||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| - | git status: Display the current status of the repository, including staged and unstaged changes. | + | ===== .git/config ===== |
| - | git diff: Display the difference between the current state and the last commit. | + | Random stuff one can use in their git config file: ~/somerepo/.git/ |
| - | git checkout < | + | ==== User details ==== |
| - | git branch: Display a list of local branches. | + | < |
| + | [user] | ||
| + | email = username@example.com | ||
| + | name = username | ||
| + | </ | ||
| - | git branch < | + | You can add this manually, or use the cli commands to populate the file with this information, |
| - | git checkout -b <branch_name>: Create and checkout a new branch. | + | <code bash> |
| + | git config user.email " | ||
| + | git config user.name " | ||
| + | </ | ||
| - | git merge < | + | ==== Aliases ==== |
| - | git rebase < | + | Setting up some short-cut commands for frequently used commands |
| - | git fetch: Download new changes from the remote repository. | + | < |
| + | [alias] | ||
| + | st = status | ||
| + | ci = commit | ||
| + | br = branch | ||
| + | co = checkout | ||
| + | df = diff | ||
| + | lg = log -p | ||
| + | lol = log --graph --decorate --pretty=oneline --abbrev-commit | ||
| + | kama = log --graph --pretty=format:\"%h - %cr - %cN - %s - %b\" --all | ||
| + | ls = ls-files | ||
| + | </ | ||
| - | git pull: Fetch and merge changes from the remote repository. | ||
| - | git push: Upload local changes to the remote repository. | + | ==== Formatting ==== |
| - | git stash: Save changes that have not yet been committed to a temporary stash. | + | Funky colors |
| - | git stash apply: Apply changes from a stash to the working tree. | + | < |
| + | [color] | ||
| + | ui = auto | ||
| + | [color " | ||
| + | current = yellow reverse | ||
| + | local = yellow | ||
| + | remote = green | ||
| + | [color " | ||
| + | meta = yellow bold | ||
| + | frag = magenta bold | ||
| + | old = red bold | ||
| + | new = green bold | ||
| + | whitespace = red reverse | ||
| + | [color " | ||
| + | added = yellow | ||
| + | changed = green | ||
| + | untracked = cyan | ||
| + | </ | ||
| - | git stash drop: Remove a stash from the stash list. | ||