Last active
May 21, 2025 12:20
-
-
Save StudioEtrange/0c72e98ca981e5013371cc80f4ad6460 to your computer and use it in GitHub Desktop.
Various git tips
-
get all remote branch (except HEAD) intto a local branch
git fetch --all for remote in $(git branch -r | grep -v '/HEAD'); do branch=${remote#origin/} git branch --track "$branch" "$remote" 2>/dev/null done
-
update all local branch from remote
for b in $(git for-each-ref --format='%(refname:short)' refs/heads/); do git checkout "$b" && git pull --ff-only done git checkout -
-
Delete 4 last commits from git history, replace them with only one commit, and push this new history to git server
git reset --soft HEAD~4
-
Create only one commit with the changes of previous deleted commits
git add . git commit -m "one commit with content of 4 deleted commit"
-
Push this new history to git server
git push --force -u origin main
-
Create a new branch with the content of all changes in git history into only one commit
git branch new_branch $(echo "init message" | git commit-tree HEAD^{tree})
-
Push this new history to git server and replace the main branch
git push --force -u origin new_branch:main
-
Delete new branch and replace main branch history with the new one
git branch -d new_branch git fetch origin git reset --hard origin/main
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment