Last active
February 11, 2024 20:47
-
-
Save AdrienHorgnies/23775549132721cfe92fc4dd60dadb50 to your computer and use it in GitHub Desktop.
Scripts to create basic branching cases any dev should learn to solve
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
HERE=$(dirname $(realpath $0)) | |
rm -rf local remote.git | |
git init --bare $HERE/remote.git | |
git clone $HERE/remote.git local | |
cd $HERE/local | |
git init | |
cat > txt <<EOF | |
1 | |
2 | |
3 | |
EOF | |
git add txt | |
git commit -m "initial commit" | |
git push -u | |
sed -i 's/2/LOCAL-ONLY/g' txt | |
git add txt | |
git commit -m "2 becomes LOCAL-ONLY" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
HERE=$(dirname $(realpath $0)) | |
rm -rf $HERE/local $HERE/remote.git | |
git init --bare $HERE/remote.git | |
git clone $HERE/remote.git local | |
cd $HERE/local | |
git init | |
cat > txt <<EOF | |
1 | |
2 | |
3 | |
EOF | |
git add txt | |
git commit -m "initial commit" | |
git push -u | |
sed -i 's/2/REMOTE-ONLY/g' txt | |
git add txt | |
git commit -m "2 becomes REMOTE-ONLY" | |
git push | |
git reset --hard HEAD~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
HERE=$(dirname $(realpath $0)) | |
rm -rf local remote.git | |
git init --bare $HERE/remote.git | |
git clone $HERE/remote.git local | |
cd $HERE/local | |
git init | |
cat > txt <<EOF | |
1 | |
2 | |
3 | |
EOF | |
git add txt | |
git commit -m "initial commit" | |
git push -u | |
sed -i 's/2/REMOTE-ONLY/g' txt | |
git add txt | |
git commit -m "2 becomes REMOTE-ONLY" | |
git push | |
git reset --hard HEAD~ | |
sed -i 's/2/LOCAL-ONLY/g' txt | |
git add txt | |
git commit -m "2 becomes LOCAL-ONLY" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
HERE=$(dirname $(realpath $0)) | |
$HERE/status.sh | |
cd $HERE/local | |
ahead=$(git rev-list main ^origin/main --count) | |
late=$(git rev-list ^main origin/main --count) | |
if [ $ahead -gt 0 ] && [ $late -gt 0 ]; then | |
set +e | |
git merge origin/main --no-commit --no-ff | |
merge_status=$? | |
set -e | |
git merge --abort | |
if [ $merge_status -eq 0 ]; then | |
git rebase origin/main | |
git push origin main | |
fi | |
elif [ $ahead -gt 0 ]; then | |
git push origin main | |
elif [ $late -gt 0 ]; then | |
git rebase origin/main | |
fi | |
$HERE/status.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HERE=$(dirname $(realpath $0)) | |
GD=$HERE/local/.git | |
ahead=$(git --git-dir=$GD rev-list main ^origin/main --count) | |
late=$(git --git-dir=$GD rev-list ^main origin/main --count) | |
if [ $ahead -gt 0 ] && [ $late -gt 0 ]; then | |
echo " out of sync" | |
elif [ $ahead -gt 0 ]; then | |
echo " local ahead of remote" | |
elif [ $late -gt 0 ]; then | |
echo " local behind remote" | |
else | |
echo " sync" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
HERE=$(dirname $(realpath $0)) | |
rm -rf local remote.git | |
git init --bare $HERE/remote.git | |
git clone $HERE/remote.git local | |
cd $HERE/local | |
git init | |
cat > txt <<EOF | |
1 | |
2 | |
3 | |
EOF | |
git add txt | |
git commit -m "initial commit" | |
git push -u |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
HERE=$(dirname $(realpath $0)) | |
rm -rf local remote.git | |
git init --bare $HERE/remote.git | |
git clone $HERE/remote.git local | |
cd $HERE/local | |
git init | |
cat > txt <<EOF | |
1 | |
2 | |
3 | |
EOF | |
git add txt | |
git commit -m "initial commit" | |
git push -u | |
sed -i 's/1/REMOTE-ONLY/g' txt | |
git add txt | |
git commit -m "1 becomes REMOTE-ONLY" | |
git push | |
git reset --hard HEAD~ | |
sed -i 's/3/LOCAL-ONLY/g' txt | |
git add txt | |
git commit -m "3 becomes LOCAL-ONLY" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment