-1

I work a little bit with alias on mac environment, and it was very useful. But i want to make some more boosting in my work using aliases. Now i want to make the add files, commit, and push to be done with aliases. So, i create an alias but it did not work; Here is the code

alias track="trackFunction() { git add .;  git commit %@; git push}"

The output be like that:

error: pathspec '%@' did not match any file(s) known to git.

So, i hope you guide me in this, because i'm new in all these stuff of work.

Mifeet
  • 12,949
  • 5
  • 60
  • 108
Islam.Ibrahim
  • 789
  • 6
  • 19

2 Answers2

2

When you call the alias, you want the content of trackFunction to be executed. But what you have defined is "when I call track, define function trackFunction".

Since you want your alias to accept parameters, you can use this (see this answer about parameters for alias):

trackFunction() { git add .;  git commit "$@"; git push; }
alias track=trackFunction

But since you can already name your function track, you don't really need an alias, you can just put the function definition into your .bashrc or .profile file.

As a side note, I don't know what your intended workflow is, but you may want to include git pull before your git push to avoid rejections.

Community
  • 1
  • 1
Mifeet
  • 12,949
  • 5
  • 60
  • 108
  • 1
    git add or git commit may fail, so I'd make all that conditional: `func() { git add . && git commit "$@" && git push; }` – glenn jackman May 14 '16 at 16:43
2

I think you just have a typo in the git commit %@. It should be a $@ instead of the %@ so you can pass parameters like -m 'Commit message'.

I also think writing a function is not necessary here. I have just successfully tested alias track="git add .; git commit" on a linux machine by calling track -m 'Commit message'.

hdlgi42
  • 74
  • 5
  • Aliases don't use placeholders for parameters, so by chance your alias worked. Your alias expands to `git add .; git commit $@ -m 'message'`. Apparently your current shell has an empty set of parameters. You just want `alias track="git add .; git commit"` – glenn jackman May 14 '16 at 16:45
  • @glennjackman I did try what you and dendress said, but did not work. – Islam.Ibrahim May 18 '16 at 13:10
  • 1
    "did not work" is the worst possible description of a problem. What actually happened, and how does that differ from what you expected to happen. Edit your question and show us evidence (cut and paste from your terminal) – glenn jackman May 18 '16 at 21:38