Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename repository #390

Closed
afeld opened this issue Aug 30, 2013 · 6 comments
Closed

Rename repository #390

afeld opened this issue Aug 30, 2013 · 6 comments

Comments

@afeld
Copy link

afeld commented Aug 30, 2013

When I'm working on a new project, I find myself renaming it after I realize what it's really about. This is a multi-step manual process:

  1. Navigate to the project settings page
  2. Type in the new name
  3. Copy the new Git URL
  4. git remote set-url origin ...

Would be great to have this as a one-liner (with a confirmation) using hub. My proposal:

$ hub rename new-repo
Are you sure you want to rename this repository [Ny]? y
Your repository can now be found at https://github.com/USER/new-repo.
@mislav
Copy link
Owner

mislav commented Aug 31, 2013

Yeah, a 2-step process including web + command-line sucks. It would be great to encapsulate this, but I'm wary of adding new commands with generic-sounding names. I don't want to clash with somebody's custom commands or aliases.

I'm also not sure about the usefulness of the command. Sure, it's nice to have that one time when you rename a repo, but maybe my time implementing it and maintaining it will be greater than the total time I save for people in their workflows. It just doesn't happen that often. I need to think about this idea, so I'll leave this open.

@afeld
Copy link
Author

afeld commented Sep 1, 2013

My strategy for the set of plugins I've started collecting has been to make longer, more descriptive names for each command, then encourage users to create their own more convenient aliases. In this case, could be something like rename-repository.

sttts pushed a commit to sttts/hub that referenced this issue Nov 28, 2017
Fix recognition logic for vi editor variants again

Fixes mislav#390.
@mislav
Copy link
Owner

mislav commented Jan 26, 2019

After some consideration, I have decided that—for now—this is best implemented in user scripts, rather than maintained in hub core. Now that there is a new hub api command, I will close this feature request and leave implementing this as an exercise to the reader. https://github.com/github/hub/releases/tag/v2.8.3 #2016

For example:

hub api -XPATCH repos/{owner}/{repo} -f name=my-new-name
# (parse out the new URL from server response)
git remote set-url origin <NEW-URL>

Thank you for suggesting!

@mislav mislav closed this as completed Jan 26, 2019
@gko
Copy link

gko commented Apr 4, 2019

or with an alias

[alias]
  set-url = remote set-url origin
  rename-repo = "!f() { hub api --flat -XPATCH repos/{owner}/{repo} -f name=$1 | grep .ssh_url | awk '/.ssh_url/ {print $2}' | xargs git set-url; }; f"

so that you run git rename-repo <something>

P.S. thank you to @mislav and GitHub for hub api. It's amazing!

@ajorpheus
Copy link

ajorpheus commented Dec 18, 2019

A slight modification to @gko's alias to rename the current directory to match the repo name:
(note that if your prompt has the current directory in it, the change won't be reflected there unless you cd back into the new dir. Doing so in the alias does not work)

[alias]
   set-url = remote set-url origin
   rename-repo = "!f() { \
                          hub api --flat -XPATCH repos/{owner}/{repo} -f name=$1 | grep .ssh_url | awk '/.ssh_url/ {print $2}' | xargs git set-url ; \                       
                          mv $(pwd) $(pwd)/../$1 ; \
                       }; f "

@SwiftWinds
Copy link

A slight modification to @gko's alias to rename the current directory to match the repo name:
(note that if your prompt has the current directory in it, the change won't be reflected there unless you cd back into the new dir. Doing so in the alias does not work)

[alias]
   set-url = remote set-url origin
   rename-repo = "!f() { \
                          hub api --flat -XPATCH repos/{owner}/{repo} -f name=$1 | grep .ssh_url | awk '/.ssh_url/ {print $2}' | xargs git set-url ; \                       
                          mv $(pwd) $(pwd)/../$1 ; \
                       }; f "

Putting this in my .gitconfig gave me a bad config line. I removed the backslashes and put it all on one line, and it worked. Leaving this comment here for posterity's sake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants