Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using git, how to avoid rebase and push?

Tags:

git

github

I think the only rule about rebase and push is that

After commits are pushed to a public repo, don't rebase and push

But is it true that if we only use git push or git push origin <branch-name> and never use the --force or -f flag, then it can never happen?

like image 416
nonopolarity Avatar asked Jan 16 '23 15:01

nonopolarity


2 Answers

If your public repo is a bare repo (meaning you can rebase anything directly on the public repo itself), and if you set the git config receive.denyNonFastForwards and receive.denyDeletes to true, then you should be ok.

If set to true, git-receive-pack will deny a ref update which is not a fast-forward. Use this to prevent such an update via a push, even if that push is forced.

If set to true, git-receive-pack will deny a ref update that deletes the ref. Use this to prevent such a ref deletion via a push.

See also "Is there a way to configure git repository to reject 'git push --force'?".

Note that those settings aren't available directly for a GitHub repo, for instance.

like image 78
VonC Avatar answered Jan 27 '23 05:01

VonC


It is true (I think) that the remote repo will never end up in a "bad" state if you don't use --force, so you can't do it accidentally.

But if you rebase commits that are already on the remote, your local repo might end up in a state where you can't push to the remote repo without going through some gymnastics that defeat the point of the rebase anyway.

like image 42
Danica Avatar answered Jan 27 '23 05:01

Danica