1

I want to have an alias which lets you add a file, commit and push it.

I started off with this:

[alias]
    acp = "!f() { git add $1; }; f"

But whenever I put in an input, I get a file not found error:

fatal: pathspec 'test.txt' did not match any files

Ideally I want to be able to write:

git acp 'myfile.txt' 'my commit message'

I have this working, but I can't make it work with an input for add:

acp2 = "!f() { git add --all; git commit -m \"${1:-commit}\"; git push origin master; }; f"
1
  • What is not working when you have an input argument for add? Changing --all to $1 and ${1:-commit} to ${2:-commit} should work fine. Commented May 26, 2016 at 9:27

1 Answer 1

1
[alias]
acp = "!f() { git add \"$1\"; git commit -m \"${2:-commit}\"; git push origin master; }; f"

This should be enough to work with your syntax:

git acp 'myfile.txt' 'my commit message'

I tested this as follows:

$ echo>test
$ git acp test "the message"
[master 9b81eb2] the message
 1 file changed, 1 insertion(+)
 create mode 100644 test

$ cat .git/config
...
[alias]
    acp = "!f() { git add \"$1\"; git commit -m \"${2:-commit}\"; }; f"
$
Sign up to request clarification or add additional context in comments.

4 Comments

I still get the same error. The file is definitely in the directory.
Running the same version. I can't even get acp = "!f() { git add \"$1\"; }; f" to work.
And this is in .git/config, and your current working directory is the project root directory?
Yes, that's right. Running the shortened version above without any input doesn't yield anything if that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.