0

I know I can use git remote set-url origin to change the URL of a remote repo? On my Linux machine I run something like

git remote set-url origin ~/projects/test.git

but git always changes the relative path into an absolute one such as /home/user/projects/test.git.

Can I prevent this behaviour?

2
  • 4
    Just between us: ~/projects/test.git isn't what's usually known as a relative path. A relative path is more something like: ../file, or subdir/file. projects/test.git is relative to ~, but the resulting path is no less absolute. Commented Nov 12, 2013 at 16:44
  • You're right of course ... Commented Nov 13, 2013 at 17:18

2 Answers 2

1

The ~ is probably expanded by your shell in that command (for example, if you are using bash see 'tilde expansion' in http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_04.html).

You might get what you want by quoting the url with single quotes like this: git remote set-url origin '~/projects/test.git'.

Edit: I don't think having a tilde path as a remote is a good idea though. I'm not sure how the expansion is made. As mentioned in the comments, git is a mix of c programs and bash scripts. This could make the tilde expansion fail under certain command and work for others.

Sign up to request clarification or add additional context in comments.

5 Comments

You might be able to actually get the config parameter set to include the tilde that way, but I'm not entirely sure git will know what to do with it after that - does git do tilde-expansion?
@twalberg I'm not sure who does the expansion... it might be a shell script called by the git command doing it. It does work under cygwin though.
Since git is a mixture of shell script and compiled binaries, I would want to do some extensive testing to make sure that all the tools (at least the ones I need on a regular basis) work well with the tilde syntax. It's quite possible that git is ok with it, though.
I tried it with double quotes and it works, thanks for pointing it out. BTW, the reason why I need this is because I share some repositories between different machines. They all have different usernames, but the same directory structure inside the user's home directory.
This post confirms (or at least suggests) the same, to use ~ -- stackoverflow.com/a/14349254/1277343
0

It’s simply is because ~ is shorthand that expands to the absolute path of the current user’s home directory.

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.