This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| cheatsheet:git [2023/02/17 00:08] – [other common commands] kamaradski | cheatsheet:git [2023/07/24 08:46] (current) – [other common commands] kamaradski | ||
|---|---|---|---|
| Line 45: | Line 45: | ||
| --keep: Keep changes in both the working tree and the index (staging area). | --keep: Keep changes in both the working tree and the index (staging area). | ||
| </ | </ | ||
| + | |||
| + | |||
| + | ===== Use git stash to move code between branches ===== | ||
| + | |||
| + | 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. | ||
| + | |||
| + | Here is how I do it: | ||
| + | |||
| + | < | ||
| + | git stash // stash your changes | ||
| + | git checkout feature_branch // Navigate to your feature branch (or create and checkout a new branch: git checkout -b feature_branch | ||
| + | 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 | ||
| + | </ | ||
| + | |||
| ===== other common commands ===== | ===== other common commands ===== | ||
| Line 65: | Line 82: | ||
| * '' | * '' | ||
| * '' | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| ===== .git/config ===== | ===== .git/config ===== | ||