User Tools

Site Tools


cheatsheet:git

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
cheatsheet:git [2023/02/17 00:08] – [other common commands] kamaradskicheatsheet: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).
 </code> </code>
 +
 +
 +===== 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:
 +
 +<code>
 +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
 +</code>
 +
  
 ===== other common commands ===== ===== other common commands =====
Line 65: Line 82:
   * ''git pull'': Fetch and merge changes from the remote repository.   * ''git pull'': Fetch and merge changes from the remote repository.
   * ''git push'': Upload local changes to the remote repository.   * ''git push'': Upload local changes to the remote repository.
-  * ''git stash'': Save changes that have not yet been committed to a temporary stash. 
-  * ''git stash apply'': Apply changes from a stash to the working tree. 
-  * ''git stash drop'': Remove a stash from the stash list. 
  
 ===== .git/config ===== ===== .git/config =====
cheatsheet/git.1676592533.txt.gz · Last modified: 2023/02/17 00:08 by kamaradski