Wednesday, May 19, 2021

GIT Basics - Stashing into branch

git status

modified: index.html

mate simple.html

mate man.txt


git status --> has 3 modified files index.html, simple.html, man.txt


let's add one file 

git add index.html


git status

-------------------------------

Changes to be committed:

modified: index.html

Changes not staged for commit:

modified:man.txt

modified:simple.html

now let's create an untracked file

mate new.md


git status

--------------------------------

Changes to be committed:

modified: index.html

Changes not staged for commit:

modified:man.txt

modified:simple.html

Untracked files:

new.md

stash all files

git stash --u --> stash all files including untracked files


git status -> clean


Apply this stash to a new branch

----------------------------

git stash branch {name of the branch}

git stash branch newbranch


This will make few steps

1. create new branch - 'newbranch'

2. switch to newly create branch - 'newbranch'

3. apply all stash changes

4. drop the stash


git stash list -> no stash items in the list

git status --> will give the same status we had on 'master' prior to stash

--------------------------------------

Changes to be committed:

modified: index.html

Changes not staged for commit:

modified:man.txt

modified:simple.html

Untracked files:

new.md

1. remove new.md file and add rest of the files to git staging area

rm new.md

git add .

git status

---------

Changes to be committed:

modified: index.html

modified:man.txt

modified:simple.html

git commit

git checkout master

git merge newbranch

git branch -d newbranch

git branch

*master

No comments:

Post a Comment