garethb
garethb

Reputation: 4041

Git How to tag a remote branch

I'm trying to create a script that will loop through all the branches on our server and archive old branches.

To get the list of branches I'm using the command

git branch -r

I then want to tag each branch, so inside a foreach loop

git tag archive/branchname branchname

However when I run the tag command I get an error

error: branch 'branchname' not found

I've also tried with

git tag archive/branchname origin/branchname

and get the same error, except this time its origin/branchname not found

tldr;

How can I tag a branch on remote?

Upvotes: 1

Views: 188

Answers (1)

VonC
VonC

Reputation: 1323203

You should be able to tag a remote remote branch, as long as git branch -avv shows you:

remotes/origin/abranch

I tested git tag archive/aTag origin/aBranch (lightweight tag) successfully, as long as a tag "archive" itself did not exist already.

Upvotes: 1

Related Questions