GIT: Profesjonalny workflow ze stash + temp‑stash + cherry‑pick

🎯 Cel workflow

  • pracujesz swobodnie bez commitów „na brudno”,
  • stashujesz zmiany jako „koszyki robocze”,
  • przenosisz je między komputerami przez branch temp-stash,
  • wybierasz konkretne zmiany cherry-pickiem,
  • historia pozostaje czysta i logiczna.

1️⃣ Tworzenie stashy podczas pracy

Zapisz zmiany bez commitowania:

git stash push -m "opis zmian"

Lista stashy:

git stash list

2️⃣ Branch temp-stash jako magazyn commitów

Utwórz go raz:

git checkout -b temp-stash

3️⃣ Zamiana stash → commit na temp-stash

Dla każdego stashu:

git checkout temp-stash
git stash apply stash@{N}
git add .
git commit -m "stash: opis"

Po tym stash@{N} możesz usunąć:

git stash drop stash@{N}

4️⃣ Przeniesienie stashy na GitHuba

git push origin temp-stash

Teraz stashy możesz używać na dowolnym komputerze.

5️⃣ Cherry-pick wybranych zmian na docelowe branche

Aby sprawdzić jakie są <hash>

git checkout temp-stash 
git log --oneline

lub wersja graficzna, daje wizualne drzewko commitów — idealne, gdy masz kilka stashy zamienionych w commity

git log --oneline --graph --decorate

Przykład dołączenia wybranego commita do auth

git checkout auth
git cherry-pick <hash_commita>

Inny stash na inną gałąź:

git checkout authorization
git cherry-pick <hash_innego_commita>

6️⃣ Czyszczenie po zakończeniu

Jeśli branch spełnił swoją rolę:

git branch -D temp-stash
git push origin --delete temp-stash

Alias Pack — 2× szybsza praca

Dodaj do ~/.gitconfig:

ini

[alias]
  sl = stash list
  sa = "!f() { git stash apply stash@{$1}; }; f"
  sd = "!f() { git stash drop stash@{$1}; }; f"
  ss = "!git stash push -m"
  ts = "!git checkout temp-stash"
  sc = "!f() { git add . && git commit -m \"stash: $1\"; }; f"
  cp = "!f() { git cherry-pick $1; }; f"
 // gl = log --oneline --graph --decorate //wersja podstawowa
  gl = log --oneline --graph --decorate --pretty=format:'%C(yellow)%h%Creset %Cgreen(%cr)%Creset %C(bold blue)%an%Creset %Creset %s' //wersja rozszeżona

Co dostajesz:

AliasDziałanie
git sllista stashy
git ss "opis"stash z opisem
git sa 0apply stash@{0}
git sd 0drop stash@{0}
git tsszybki skok na temp-stash
git sc "opis"commit zmian jako stash-commit
git cpcherry-pick
git glczytelny graficzny log

🧭 Minimalny workflow w praktyce

1. Pracujesz → stash:

git ss "USER model update"

2. Przenosisz stash na temp-stash:

git ts
git sa 0
git sc "USER model update"
git sd 0
git push

3. Na innym komputerze:

git fetch
git ts

4. Przenosisz wybrane zmiany:

git checkout auth
git cp <hash>