Skip to content

Instantly share code, notes, and snippets.

@marando
Created December 3, 2021 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marando/ea69094a155aebe3d42f4438a976fede to your computer and use it in GitHub Desktop.
Save marando/ea69094a155aebe3d42f4438a976fede to your computer and use it in GitHub Desktop.
Random Git Snippets

Random Git Snippets

Archive a Branch

  1. Switch to the main branch:

    git checkout master
  2. Tag the branch and push to origin:

    git tag archive/some-old-branch some-old-branch
    git push --tags
  3. Delete the local and remote branch:

    git branch -d some-old-branch
    git push origin :some-old-branch
  4. Bonus: To restore a branch from an archive tag:

    git checkout -b restored-branch archive/some-old-branch

Sort Branches by Last Commit Date

git branch --sort=committerdate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment