0

I was reading through this answer to a question. I've always worked with only one repository until now so I never thought much about the git syntax but this answer made me realize that git's syntax might be backwards to what's conventional. (at least for the push command)

As I understand it, in the accepted answer, @jweyrich makes a new repository called all which acts as a repository except it actually represents two repositories in his example. At the end he writes that we can push what we want to commit to the remote repository with git push all master.

If I'm understanding this correctly, git is the only api I know of where you specify <command> <dest> <source> as opposed to <command> <source> <dest>. Copying files, moving files, etc... Is all done with the latter syntax. Even AWS s3 buckets use the syntax <command> <source> <dest>.

Why does git seem to have backwards syntax? Am I one of the few that for whom this wasn't obvious when starting with git?

financial_physician
  • 1,672
  • 1
  • 14
  • 34
  • 2
    It's not backwards. The have-it-all syntax of git-push is `git push remotename source1:dest1 source2:dest2 source3:dest3 ..` ignoring --switches. Note that you can push many branches, and specify different target branch for each of them. For example `git push origin myLocalBranch:targetServerBranch` assuming typical name 'origin' for the remote server. Consider other kinds of 'pushes' to be shortcuts or abbreviations for this long syntax. For example `git push origin :targetBranch` deletes it (no source). Another: `git push origin foobar` - assumes that sourcename=destname, and so on. – quetzalcoatl Aug 26 '20 at 00:58
  • @quetzalcoatl But `mv ... ` is also a thing. – Mateen Ulhaq Aug 26 '20 at 00:59
  • @quetzalcoatl your examples show that git is consistent with itself but it doesn't show that git is consistent with another api. – financial_physician Aug 26 '20 at 01:52

1 Answers1

0

That's because you very often know what <source> is. 99% of the time, it's the current branch. So:

git push <destination>

is much easier to do than

git push <destination> <current_known_source>

I think git rebase presents a stronger case, though. To rebase <source> onto <destination>, I am almost always rebasing the current branch onto <destination>. Thus, I save the pain of specifying <source> each time:

git rebase <destination>
Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
  • I've never used the first shorthand. That's good to know about – financial_physician Aug 26 '20 at 01:04
  • 1
    @financial_physician Even shorter: you can often just do `git push` without any arguments at all since usually you're pushing the current branch (e.g. `master`) to a single remote repository (e.g. `origin`). – Mateen Ulhaq Aug 26 '20 at 01:05