Create Two Branches From Same Commit
How to create different branches from same commit using git with batch file
To create two different branches with differnt commits from same commit, we can use the below content as batch file.
git tag temp_tag
:: To check the list of local branch
git branch
git checkout myfirstbranch
echo off
echo "This is a Sample File for testing" > "mytestfile1.txt"
echo on
git add "mytestfile1.txt"
git commit -m "added a file in new branch"
:: Change to root tag
git checkout tags/temp_tag
git checkout mysecondbranch
echo off
echo "This is another file for testing" > "mytestfile2.txt"
echo on
git add "mytestfile2.txt"
git commit -m "added another file in another branch"
:: remove the local temp branch
git tag -d temp_tag
:: push the branches to origin
git push origin myfirstbranch:myfirstbranch
git push origin mysecondbranch:mysecondbranch
:: checkout to diff branch if you want
git checkout develop
To keep the base location (initial commit), a temporay tag is created in local to checkout later. This tag will be deleted from local to avoid further issue.
You can also use the Head~1 in checkout instead of tag.