Reputation: 215
Example below shows how to list remote tags, without cloning the repo:
$ git ls-remote --tags https://<TOKEN>@github.com/user/repo.git
# 0afdaf971...09a refs/tags/tagname
How to remotely edit/add/del new tag like example above without having to clone the repo?
git push origin :tagname
Requires of cloning the repo.
Is there a way to achieve it without cloning repo?
Upvotes: 3
Views: 1212
Reputation: 2863
Found this too. If the commit you want to tag is the latest of a particular branch, you can download only that commit like this:
git clone --bare --single-branch --branch $BRANCH_NAME --depth=1 --filter=tree:0 --filter=blob:none --filter=object:type=commit $REPOSITORY_URL .git
This requires a later version of git which supports --filter
and --filter=object:type=commit
. Besides the commits, this seems to also download the hooks
directory, which on my repository is 40k (I think this is with an empty list of hooks).
Then you can tag it as usual:
git push origin +$BRANCH_NAME:refs/tags/${TAG_NAME}
Upvotes: 0
Reputation: 2863
I figured out how to do this in a generic way in git (this may break in the future).
The following variables are used:
BRANCH_NAME # I think this can be anything
REPOSITORY_URL
COMMIT_HASH # The commit to tag
TAG_NAME # The name of the tag
For git push
to work, you need to have a .git
directory created as follows:
mkdir -p .git/objects .git/refs
echo 'ref: refs/heads/$BRANCH_NAME' > .git/HEAD
printf '[remote "origin"]\n url = $REPOSITORY_URL'
Additionally, you need to have a "commit" object in the objects directory. This file has a bit of information that's difficult to transfer over and re-create. It's easier to just copy the file over (it's a small file). The following will get the file:
mkdir -p output_directory/objects/${COMMIT_HASH:0:2}/
cp .git/objects/.git/objects/${COMMIT_HASH:0:2}/${COMMIT_HASH:2} output_directory/objects/${COMMIT_HASH:0:2}/${COMMIT_HASH:2}
And then when you're ready, you can copy this file to the new stub git repository in the .git/objects/${COMMIT_HASH:0:2}/${COMMIT_HASH:2}
directory.
Then in the new stub git directory, push the new tag like this:
git push +${COMMIT_HASH}:refs/tags/${TAG_NAME}
Remember to set up your git credentials. This can be done as follows:
git config credential.helper store
echo "https://$GIT_USERNAME:$GIT_PASSWORD@$GIT_REPOSITORY_DOMAIN" > ~/.git-credentials
Upvotes: 0
Reputation: 215
@xerx593
Thank you for pointing to the right direction, here is solution:
curl --user "username:password" --data '{"tag_name":"v1.1","target_commitish":"master"}' \
-X POST https://api.github.com/repos/:owner/:repo/releases
Upvotes: 2