I'm trying to get my makefile to check that it's running on the correct branch and throw and error if not.
I'm using ifneq
to compare them and git rev-parse --abbrev-ref HEAD
to get the checked out branch, but it will not see them as equal. How can I fix this?
Right now the the code looks like this:
ifneq ($(git rev-parse --abbrev-ref HEAD), master)
$(error Not on branch master)
else
git checkout gh-pages
git merge master
git checkout master
endif
Thanks.
Git already only pulls the current branch. If you have branch set up as a tracking branch, you do not need to specify the remote branch. git branch --set-upstream localbranch reponame/remotebranch will set up the tracking relationship. You then issue git pull [--rebase] and only that branch will be updated.
Git stores all references under the . git/refs folder and branches are stored in the directory . git/refs/heads. Since branch is a simple text file we can just create a file with the contents of a commit hash.
Git branch_name Branch is a beauty of git. You can work with coworkers without any interference with them. This will create a local branch with the name branch_name . Then you can switch your branch to this by git checkout branch_name .
There is no such make function as $(git ...)
, so that variable reference expands to the empty string. You're always running:
ifneq (, master)
which will be always true.
You want to use the shell
GNU make function:
ifneq ($(shell git rev-parse --abbrev-ref HEAD),master)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With