3

How to edit tag in github, without cloning the repo from command line?

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?

8
  • Possible duplicate of Create a tag in a GitHub repository Commented Feb 5, 2019 at 22:25
  • ( stackoverflow.com/a/18223354/592355 -> Creating tags through GitHub's web interface) Commented Feb 5, 2019 at 22:26
  • Thanks for the answer, but i need it from command line. Commented Feb 5, 2019 at 22:35
  • 1
    ..then you must clone! (what do you want to tag otherwise? ..a (non) empty folder/repository??) ..of course the work around: "call github from cmd" (with curl, when all else fails)) Commented Feb 5, 2019 at 22:36
  • there is remote repository, I am looking for solution to remotely update the tag, to trigger builds. Commented Feb 5, 2019 at 22:37

3 Answers 3

2

@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 
Sign up to request clarification or add additional context in comments.

Comments

0

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 

Comments

0

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} 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.