Git command to commit all changes including files removed or created

After making changes to files already tracked by git I usually do a:

git commit -a -m "a message describing what you did"

followed by

  • switching branches in git - when will i get “You have local changes cannot switch branches.”?
  • How can I export a large Perforce repository into a different version control system without losing the history?
  • cant configure dataSource and delegate
  • could not resolve host github.com error while cloning remote repository in git
  • git - how to get the full message from git merge --log
  • How to commit no change and new message?
  • git push origin master
    

    to commit and then push all changes to my Github account. The first command however does not work for commiting files either added or removed. To do that I would have to first type:

    git add -A
    

    as mentioned here: How to commit and push all changes, including deletes?.

    In this other question Git commit all files using single command the accepted answer indicates that the only way to apply the full commit (ie: including files added or removed, not only edited) and then the push is by combining them with the && command like so:

    git add -A && git commit
    

    which in my case would look like:

    git add -A && git commit -a -m "a message describing what you did" && git push origin master
    

    Now for the question(s): is this large command correct? Is there a way to create a new git command to apply these three commands all at once? Furthermore: is this merging of commands recommended or discouraged? If so, please state the reason.


    Edit

    I immediately regret this decision: Edit last pushed commit's message.

  • Git .git/info/refs not valid: is this a git repository?
  • Git: How to create patches for a merge?
  • Fail upload jar into github with maven
  • Change local reference for remote branch
  • Can't push new git repository to github
  • Why does global .gitignore file not appear to work_?
  • 3 Solutions collect form web for “Git command to commit all changes including files removed or created”

    Looks correct to me.

    You could create an alias for the command by executing

    git config --global alias.commitall '!func(){ git add -A && git commit -am "$1" && git push origin master; }; func'
    

    Then you could commit all changes by entering

    git commitall "a message describing what you did"
    

    Yeah. That large command is actually correct. It will allow you to commit everything inside a given directory in a repo, including newly created / untracked files.

    Yes, you can create a new git command (actually, an alias) like this:

    [alias]
    acp = "!f(){ git add -A && git commit -am "$1" && git push origin master; };f"
    

    The above alias must go inside your global git configuration (at ~/.gitconfig) under section labelled [alias]. Now, you can write something like: git acp <message> to run the above command.

    Merging of commands is definitely recommended and is the power that *nix provides. However, in the current case, make sure that you actually want to perform all these actions in a single step. Git assumes that you want to selectively add your changes.

    If you feel bad about typing three lines again and again, you could also use GUI tools.
    http://www.git-scm.com/downloads/guis
    By the way, as “Stonic” said, you could always create a new git command.

    Git Baby is a git and github fan, let's start git clone.