Skip to content

Instantly share code, notes, and snippets.

@quant61
Last active December 14, 2022 06:04
Show Gist options
  • Save quant61/1fb8e2c0236a74bfe8b42cee9ae2849e to your computer and use it in GitHub Desktop.
Save quant61/1fb8e2c0236a74bfe8b42cee9ae2849e to your computer and use it in GitHub Desktop.
scenario about git branches
A case where switching branches doesn't work as expected.
In my case pushing to dev was prevented by gitlab,
but someone can accidentally push things to master/main while thinking they are pushing to feature branch
#!/bin/bash
mkdir project0
cd project0
echo "create new project"
git init
git checkout -b main
echo 1 > 1
git add 1
git commit -m 1
echo "add feature1"
git checkout -b feature1
echo feature1 > feature1
git add feature1
git commit -m feature1
echo "add feature2"
git checkout -b feature2
echo "realize that we wanted to create feature2 from main"
echo "but created it from feature1 by mistake"
echo "I wanted to start from main"
git checkout main
git branch -d feature2
echo "here things goes wrong"
git checkout -b feature2
echo "I think I'm on feature2, but I'm still on main"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment