Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get remote branch name in git pre-push hook

The documentation says:

Information about what is to be pushed is provided on the hook's standard input with lines of the form:

< local ref> SP < local sha1> SP < remote ref> SP < remote sha1> LF

For instance, if the command +git push origin master:foreign+ were run the hook would receive a line like the following:

refs/heads/master 67890 refs/heads/foreign 12345

how do I access those lines in the pr-hook script?

like image 275
Gummidrum Avatar asked Feb 04 '14 15:02

Gummidrum


People also ask

Can I push git hooks to remote?

You can import a remote Git repository in to Business Central and configure a post-commit Git hook to automatically push changes to that remote repository.

How do I push a remote branch to a different name?

If you want to push to a remote branch with a different name than your local branch, separate the local and remote names with a colon: git push origin local-name:remote-name .

What is branch name in git push?

To push the branch or you can say to push the changes in the branch to the Github repo you have to run this command “git push origin <the branch name>” in our case the branch name is “main”. After pushing the changes the repo will look like and this is how you can push a branch to a remotely hosted GitHub repository.

How do you use a pre-commit hook?

If you want to manually run all pre-commit hooks on a repository, run pre-commit run --all-files . To run individual hooks use pre-commit run <hook_id> . The first time pre-commit runs on a file it will automatically download, install, and run the hook. Note that running a hook for the first time may be slow.


1 Answers

Remote branch name can be accessed using:

while read local_ref local_sha remote_ref remote_sha 
do 
    echo $local_ref
    echo $local_sha 
    echo $remote_ref
    echo $remote_sha
done 
like image 96
Krati Jain Avatar answered Sep 19 '22 16:09

Krati Jain