Here is the vlog.
๐ฅ Git Cases for Vlog (Before = Branch First, After = File First) ๐ฅ
๐ Case 1: File Created in main
, Then Switch to new-branch
(Untracked File)
- Before: Branch created first โ File created later.
- After: File created first โ Branch created later.
๐ข Case Before (Branch First, Then File)
git checkout main
git checkout -b new-branch # Create branch first
echo "Hello from Main" > file1.txt # File created in new-branch
ls # file1.txt exists โ
git checkout main
ls # file1.txt NOT present in main โ
โ
Result: File exists only in new-branch
.
๐ต Case After (File First, Then Branch)
git checkout main
echo "Hello from Main" > file1.txt # File created first
git checkout -b new-branch # Now create branch
ls # file1.txt exists โ
git checkout main
ls # file1.txt exists โ
โ
Result: File exists in both main
and new-branch
.
๐ Case 2: File Created, Then git add .
in main
, Then Switch to new-branch
- Before: Branch created first โ File created and staged later.
- After: File created and staged first โ Then branch is created.
๐ข Case Before
git checkout main
git checkout -b new-branch
echo "Content for Case 2" > file2.txt
git add .
git checkout main # Switch back to main
ls # file2.txt NOT present โ
โ
Result: File exists only in new-branch
.
๐ต Case After
git checkout main
echo "Content for Case 2" > file2.txt
git add .
git checkout -b new-branch
ls # file2.txt exists โ
git checkout main
ls # file2.txt exists โ
โ Result: File exists in both branches.
๐ Case 3: File Created, git add .
, git commit -m
in main
, Then Switch to new-branch
- Before: Branch created first โ File committed later.
- After: File committed first โ Then branch is created.
๐ข Case Before
git checkout main
git checkout -b new-branch
echo "Committed file" > file3.txt
git add .
git commit -m "Added file3.txt in new-branch"
git checkout main
ls # file3.txt NOT present โ
โ
Result: File is only in new-branch
.
๐ต Case After
git checkout main
echo "Committed file" > file3.txt
git add .
git commit -m "Added file3.txt in main"
git checkout -b new-branch
ls # file3.txt exists โ
git checkout main
ls # file3.txt exists โ
โ Result: File exists in both branches.
๐ Case 4: File Created in main
, Then Switch to new-branch
, Then git add .
and git commit -m
-
Before: Branch created first โ File committed later in
new-branch
. -
After: File created in
main
first โ Switched to new branch, then committed.
๐ข Case Before
git checkout main
git checkout -b new-branch
echo "This is Case 4" > file4.txt
git add .
git commit -m "Committed file4.txt in new-branch"
git checkout main
ls # file4.txt NOT present โ
โ
Result: File exists only in new-branch
.
๐ต Case After
git checkout main
echo "This is Case 4" > file4.txt
git checkout -b new-branch
git add .
git commit -m "Committed file4.txt in new-branch"
ls # file4.txt exists โ
git checkout main
ls # file4.txt exists โ
โ Result: File exists in both branches.
๐ Case 5: File Created in main
, git add .
, Switch to new-branch
, Then git commit -m
- Before: Branch created first โ Then file added and committed.
- After: File created and added first โ Switched branch โ Then committed.
๐ข Case Before
git checkout main
git checkout -b new-branch
echo "This is Case 5" > file5.txt
git add .
git commit -m "Committed file5.txt in new-branch"
git checkout main
ls # file5.txt NOT present โ
โ
Result: File exists only in new-branch
.
๐ต Case After
git checkout main
echo "This is Case 5" > file5.txt
git add .
git checkout -b new-branch
git commit -m "Committed file5.txt in new-branch"
ls # file5.txt exists โ
git checkout main
ls # file5.txt exists โ
โ Result: File exists in both branches.
๐ Case 6: File Created in main
, git add .
, git commit -m
, Then Switch to new-branch
and Add Another File
-
Before: Branch created first โ Then file added and committed in
new-branch
. -
After: File added and committed first in
main
โ Then switched tonew-branch
and added a new file.
๐ข Case Before
git checkout main
git checkout -b new-branch
echo "First file" > file6.txt
git add .
git commit -m "Committed file6.txt in new-branch"
echo "Second file" > file7.txt
git add .
git commit -m "Committed file7.txt in new-branch"
git checkout main
ls # file6.txt and file7.txt NOT present โ
โ
Result: Both files exist only in new-branch
.
๐ต Case After
git checkout main
echo "First file" > file6.txt
git add .
git commit -m "Committed file6.txt in main"
git checkout -b new-branch
echo "Second file" > file7.txt
git add .
git commit -m "Committed file7.txt in new-branch"
ls # file6.txt and file7.txt exist โ
git checkout main
ls # Only file6.txt exists โ
โ Result:
-
file6.txt
exists in both branches. -
file7.txt
exists only innew-branch
.
Key Takeaways
- If a file is unstaged and uncommitted, it stays only in the working directory.
- If a file is staged but uncommitted, it can cause checkout errors.
- If a file is committed in one branch, it will not appear in another branch unless merged.
๐ Final Notes:
Case | When was the branch created? | When was the file created? | Where is the file available? |
---|---|---|---|
Case Before | Before file creation | File created after switching to new-branch
|
โ
Only in new-branch
|
Case After | After file creation | File created before switching to new-branch and committed |
โ Available in both branches |