Skip to content

Instantly share code, notes, and snippets.

@StudioEtrange
Last active June 24, 2024 21:18
Show Gist options
  • Save StudioEtrange/0c72e98ca981e5013371cc80f4ad6460 to your computer and use it in GitHub Desktop.
Save StudioEtrange/0c72e98ca981e5013371cc80f4ad6460 to your computer and use it in GitHub Desktop.
Various git tips

Various git tips

store git password in a local file

git config --global credential.helper store
  • by default, password are stored in $HOME/.git-credentials

disable any credential helper

git config --system --unset credential.helper

see git log in color with graphs

git log --graph --oneline --all --decorate

image

Compress N last commits into one

  • 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
    

Compress all commit history into one

  • Create a new branch with the content of all changes of all commit of the git history

    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
    
  • Efface branche temporaire, et remplace l'historique de la branche principale avec le nouvelle historique compressé

    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