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
mainfirst → 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-branchand 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.txtexists in both branches. -
file7.txtexists 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 |