herve
herve

Reputation: 610

Is there a way, in VS Code, to warn me before pushing git changes to a distant branch?

I often do the same mistake, I do some corrections (or modifications) on my code, forgot to create a new branch for it and push it directly on the develop branch of my Gitlab repo.

Is there a way, in VS Code, to be warmed before pushing changes to a selected branch of the distant repo ?

Upvotes: 1

Views: 1471

Answers (3)

herve
herve

Reputation: 610

Since May 2022 (version 1.68), it is now possible to use git.branchProtection and git.branchProtectionPrompt to protect, directly from VS Code, some Git branches.

That's exactly what I was looking for.

See this link (at the time of writing, I can't find any documentation).

Upvotes: 1

Julian
Julian

Reputation: 36780

You could also protect the branch by making it protected and only allow pull requests in GitLab:

Require everyone to submit merge requests for a protected branch

You can force everyone to submit a merge request, rather than allowing them to check in directly to a protected branch. This setting is compatible with workflows like the GitLab workflow.

See https://docs.gitlab.com/ee/user/project/protected_branches.html#require-everyone-to-submit-merge-requests-for-a-protected-branch

The push will be rejected, just like the pre-push hook.

Upvotes: 2

rioV8
rioV8

Reputation: 28783

You have to implement a pre-push hook.

Inside the hook script examine the branch used and ask the user if he wants to push and if not return a 1 otherwise return a 0.

You can use any language you want to write the script.

Look at the .git/hooks/pre-push.sample

Upvotes: 1

Related Questions