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 |
Top comments (0)