Question

I recently renamed a remote to a new alias and the old alias (and all its commits up until the point of renaming) is still visible in the logs and consequently gitk. Running

$ git remote show old-alias 

obviously returns:

fatal: 'old-alias' does not appear to be a git repository

This is pretty annoying. How do I cleanly remove these references? Is it OK if I manually delete the

.git/logs/refs/remotes/old-alias/
.git/refs/remotes/old-alias/

directories?

Edit:

Here is the git remote -v output:

origin  git@github.com:my-user/our-repo (fetch)
origin  git@github.com:my-user/our-repo (push)
upstream        git@github.com:upstream-user/our-repo (fetch)
upstream        git@github.com:upstream-user/our-repo (push)

Here is the git log --oneline --graph --decorate output:

* 692d53f (HEAD, origin/somebranch, somebranch) Commit message                                                                                                                                 
* 9a4e794 Commit message                                                                                                                                                     
* 419376b Commit message
* 9a945bd (origin/someotherbranch, someotherbranch) Commit message
* 9a0fe3b Commit message
* 021d553 Commit message
* fa60dba Commit message
* 2d52d72 Commit message
* c59307f Commit message
* b89ae1c Commit message
* 063030c Commit message
* 97b8c77 Commit message
* ec65002 Commit message
* 38d7bb8 Commit message
* 36856fc Commit message
* 13b5065 Commit message
*   66e7dae (upstream/master, origin/master, old-alias/master, master) Commit message
|\  
| * caf7e86 Commit message
| * a0c5abe Commit message
| * 9d1a735 Commit message
| * 4e7770d Commit message
| * cd3dd89 Commit message
* |   3037432 Merge pull request message
|\ \  
| |/  
| * 12b4a01 Commit message
| * be41159 Commit message
|/  
* 8210859 Commit message
* 6b2090e Commit message
* 4b069f3 Commit message
*   1ef939c Merge pull request message
|\  
| * fc559bb Commit message
|/  
* 6fab424 Commit message
* ce10b38 Commit message
* 345128e Commit message

old-alias was changed to origin around commit 2d52d72 via git remote rename old-alias origin.

Was it helpful?

Solution

The question here has a similar issue: Why is old name of git remote sill in .git/refs/remotes?. Following the advice there, I deleted the

.git/logs/refs/remotes/old-alias/
.git/refs/remotes/old-alias/

directories manually. There are residual logs in .git/logs/HEAD and .git/logs/refs/heads/someotherbranch:

./logs/HEAD:14:6d8019... Ayberk Özgür <ayberk.ozgur@email.com> 1394819391 +0100   pull old-alias someotherbranch: Fast-forward
./logs/refs/heads/android:13:6d8019... Ayberk Özgür <ayberk.ozgur@email.com> 1394819391 +0100     pull old-alias someotherbranch: Fast-forward

I don't exactly know if those are the only traces left of old-alias or whether they may be harmful. However, I haven't encountered any issues so far.

OTHER TIPS

First, what I ended up with:

export REMOTE_NAME="old-alias" # insert your remote name
for branch in $(git branch -a | grep -o "${REMOTE_NAME}/.*") ; do
    git branch -r -d $branch
done

I had a very similar issue, although even after recklessly deleting content from my .git directory - probably don't do that! - I still had the remote references.

For me, the trick was to use the -r option to deleting a git branch: git branch -r -d as suggested by bitoiu (in the referenced answer).

I used this in conjunction with git br -a because I had ~20 orphaned remote branches and I wanted to loop over them to delete them all.

I expect since readers have git that grep has the -o option to only return the matched substring. If not, prune the leading remotes/ with your tool of choice, such as | sed -e 's/^remotes.//', which I use on QNX (although I don't have git on QNX).

Finally, if you prefer one liners, it's worth learning the sh/bash for loop one-line syntax: for branch in $(git branch -a | grep -o "old-alias/.*") ; do git branch -r -d $branch ; done

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top