Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows custom git commands

Tags:

git

windows

Say I want a new git command, git new, that makes a new branch that is up to date with origin/master.

Is there a way I can make this script and have it available in all repositories on Windows from powershell?

edit: To clarify I want a git script not a powershell function. The only reason I mentioned powershell is because I don't use git bash.

like image 283
RusinaRange Avatar asked Aug 24 '16 11:08

RusinaRange


People also ask

How do I write custom Git commands?

Writing custom git commands are simple as these three steps: 1 Create a file with a name in the given format git-mycommand. And this file should be given executable access. 2 The created file should be included in $PATH. This can be done in bashrc or in zshrc 3 Then you can run the command git mycommand in any of the git repo you have. More ...

What is the equivalent of the Git-C Custom Command?

The git-c custom command is the equivalent to typing this: git add -A git commit -m '@mac: message in command line' The command to invoke it:

How do I maintain my own Git commands?

To maintain your git commands I suggest you create your own git repository where you can place your commands in. This enables you to track changes and share your custom commands. I am using zsh so in my .zshrc file in my home directory, I added the following line to add the path to my repository to the PATH variable.

How do I run Git from a bash file?

The first line tells Unix that the file is to be executed by /bin/bash. The following command will print Hello World. Save it and now you can call your git command like the standard git commands you know. This is all you need for your setup.


Video Answer


1 Answers

You can use a git alias which uses git checkout:

git config --global alias.new 'checkout origin/master -b'

This would then be used as git new new_branch.

(Which is equivolent to git checkout origin/master -b new_branch

See the git docs for checkout. I tried the command and it worked, but when I looked at the docs, I didn't find a syntax that exactly matched my form. (Closest is git checkout [-q] [-f] [-m] [[-b|-B|--orphan] <new_branch>] [<start_point>])

Note: @axiac, I may have used the !git because it doesn't hurt, and I may have needed to do multiple commands to solve the problem, and didn't remove it when I was done.

like image 188
Thomas F Avatar answered Nov 01 '22 17:11

Thomas F