chriswalz / bit

Bit is a modern Git CLI
Apache License 2.0
6.06k stars 106 forks source link

`bit sync` assumes remote is named `origin`, override doesn't work #33

Closed mhogerheijde closed 4 years ago

mhogerheijde commented 4 years ago

I (almost) always rename the original remote repository upstream.

When I create a new repository that does not have a remote called origin:

$ git init
$ echo "# Hello World!" >> README.md
$ git commit -a -m "Add readme"
$ git remote add upstream git@github.com:mhogerheijde/somerpo.git
$ bit sync
exit status 1
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
nothing to save or commit
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using

    git remote add <name> <url>

and then push using the remote name

    git push <name>

Which is to be expected, since git itself also doesn't know. But I cannot tell bit to use a different upstream.

When I set an upstream repo for the master branch

$ git push --set-upstream upstream

Everything works as expected.

The --help output hints at that you should be able to use a different upstream:

$ bit sync --help
sync
sync origin master
sync local-branch

Usage:
  bit sync [flags]

Flags:
  -h, --help   help for sync

But this command doesn't work

$ bit sync upstream master
exit status 1
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
[...]
mhogerheijde commented 4 years ago

Oh and if it matters:

$ bit --version
bit version v0.5.10
git version 2.25.1
chriswalz commented 4 years ago

@mhogerheijde do you have a recommendation on how to determine the default remote name. For example, I could run git remote -v and then simply pick the first line which would get a upstream but not necessarily the right one in your case when there are multiple remotes

bit remote
origin
mhogerheijde commented 4 years ago

Hmm, I'd say that if there is an ambiguity that bit should ask the user. I think git also does this with multiple remotes.

In my case specifically, I have 1 remote called upstream. So I'd say pick one automatically if it is not ambiguous, and ask the user otherwise?

Not that the ambiguity could also be solved by the .git/config file where it states the remote for the current branch. This already works as expected with bit.

mhogerheijde commented 4 years ago

Ah, right, I just double checked: if no section exists for the current branch like this:

[branch="master"]
    remote = origin
    merge = refs/heads/master

git will complain about not having any information on where to push to/pull from. I usually don't notice, because I generally try to be explicit and would type git pull upstream master and thus git has all the context it needs.

bit sync, however, doesn't allow to specify the remote. That is, it does according to the help text, but it doesn't do anything.

chriswalz commented 4 years ago

@mhogerheijde Cool, that helps. In version 0.9.0 milestone you'll be able to specify remote and branch via bit sync <upstream> <branch>!

chriswalz commented 4 years ago

This is fixed with 2e0a6056c70f026587a09eea3f21317b70f2ee2b & c66f14628ecbf064e3426d1d2121829f50a07c52 as of v0.9.1. Please reopen if you have any problems

mhogerheijde commented 4 years ago

Seems to work :+1: thanks!