felvieira
1/16/2019 - 5:00 AM

Comandos Git Úteis

Salvar credenciais do git na maquina
git config --global credential.helper store

git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"

git config --global alias.lg2 " log --format='%Cred%h%Creset %s %Cgreen(%cr) %C(blue)<%an>%Creset%C(yellow)%d%Creset' --no-merges"

git config --global pull.rebase true


Deletar branch Remota
git push origin --delete develop --no-verify

Renomear Branch
git branch -m old_branch new_branch         # Rename branch locally    
git push origin :old_branch                 # Delete the old branch    
git push --set-upstream origin new_branch   # Push the new branch, set local branch to track the new remote

Fazer Git add, git commit e git push em um so comando
Making lazygit a function instead of an alias allows you to pass it an argument.
I have added the following to my .bashrc (or .bash_profile if Mac):
  
sudo nano ~/.bashrc

function lazygit() {
    git add .
    git commit -a -m "$1"
    git push
}
This allows you to provide a commit message, such as

lazygit "My commit msg"

You could of course beef this up even more by accepting even more arguments, 
such as which remote place to push to, or which branch.

Ou vc pode colocar no .gitconfig

[alias]
    cmp = "!f() { git add -A && git commit -m \"$@\" && git push; }; f"
Usage: git cmp "Long commit message goes here"

The alias can be also defined from command line, this adds it to your .gitconfig:

git config --global alias.cmp '!f() { git add -A && git commit -m "$@" && git push; }; f'



git push origin :refs/tags/<tagname>  // Delete tag from remote
git tag -fa <tagname>                 // Reset tag to current commit
git push origin master --tags         // Push tag to remote


https://medium.com/macoclock/how-to-customize-your-own-osx-linux-terminal-af24c15f7704

The easiest way would be to find the head commit of the branch as it was immediately before the rebase started in the reflog...

git reflog and to reset the current branch to it (with the usual caveats about being absolutely sure before reseting with the --hard option).

Suppose the old commit was HEAD@{5} in the ref log:

git reset --hard HEAD@{5} In Windows, you may need to quote the reference:

git reset --hard "HEAD@{5}" You can check the history of the candidate old head by just doing a git log HEAD@{5} (Windows: git log "HEAD@{5}").

If you've not disabled per branch reflogs you should be able to simply do git reflog branchname@{1} as a rebase detaches the branch head before reattaching to the final head. I would double check this, though as I haven't verified this recently.

Per default, all reflogs are activated for non-bare repositories:

[core] logAllRefUpdates = true