Git alias: Commit arguments and hit one command

I am trying to convince my colleagues to leave svn and switch to git. One of the problems I see is this: it is complex and error prone when you have to do git commit and git push separately. So I was thinking of a git ci alias that pushes the changes and pushes it directly to the server. I know how to do this, but:

The problem is that I want to give arguments like -m "" to git commit. So

git ci -m "Cool change" 

must fulfill

 git commit -m "Cool change" && git push 

How can i do this?

+6
source share
2 answers

you can "hide" git, as the "git achievement" project does. This will allow you to add scripts that look like git commands. Your main thread should be:

 git pull --rebase 

so that the story is linear, like what theyโ€™re used to in updating SVN. But you must tell them that they may need to get rid of conflicts and tell them about it or about the alias git add -A && git rebase --continue . I suggest turning on reerere and sharing these resolutions on the team with a script attached to the "alias" that you are going to do for this.

Then hide the commit with something like this:

 git add -A git commit -m "message" git pull --rebase git push origin <current branch> # or set up tracking and omit the last 2 args 

They should also be misrepresented in conflicts.

here is a link to git achievements:

http://benjamin-meyer.blogspot.com/2010/03/git-achievements.html

Although I think this does not help them in the long run, I hope this helps for now.

0
source

For the general problem of adding the arguments of one of several commands as an alias, git alias works almost the same way as a regular nix alias. The only difference is that if the alias git starts with ! , he suggested that git should be added to the command. Any arguments used in conjunction with an alias are added to insert the argument into the command login line, which requires parsing the command. See for example this question for arguments.

But for this question in particular. I agree with others that this is a useful thing. If you are going to click immediately after committing, I assume that each user has their own private private repo (only for others), so pressing "never" will work, which means that it is very different from svn; they should come from different repositories, etc.

If you instead use one public โ€œmaster repo,โ€ which everyone pulls and pushes, it would be even worse, because when the push inevitably works someday, they are trained not to use โ€œcommitโ€, and then โ€œpushโ€, but use your alias "ci" to commit and push changes; When they try to "re-commit" the changes, the second part will not be executed because the first command will not complete the success status (but instead prints no changes added to commit (use "git add" and/or "git commit -a") ) .

0
source

Source: https://habr.com/ru/post/891543/


All Articles