I want to define a shortcut (alias) for the following command:
git subtree push --prefix=_site [email protected]:mertnuhoglu/blog_datascience.git gh-pages
I want to be able to use the shortcut such that I won't need to specify the repository name. Even when using it in different repos.
Is this possible? How can I do this?
In the home directory of your user
C:\Users\<user-name>
(or in git-bash:/c/Users/<user-name>
)/home/<user-name>
/Users/<user-name>
create or open a file called
.bashrc
and append the following lineThen open a new (git-)bash and the alias
gsp
should be available.UPDATE
This update describes a more general approach, which should work for multiple subtrees and for any git repository (that has been configured accordingly).
The requested alias would require a mechanism to automatically infer
for each subtree.
As far as I know
git-subtree
only stores the hash of a commit in the remote repository that has been referenced (and possibly its history), but it does not store the address of that remote, as can be seen in the output ofgit-log
of a toy example:So, there goes the easy solution.
But what about storing the required information from the enumeration above in a config file, e.g.
.gitsubtrees
alongside each repository? That file uses a simple file format:Then add the following function to your
.bashrc
:If, for some git repository, the config file
.gitsubtrees
does not exist,gsp
won't do anything otherwise it will print the command it executes and the corresponding output.Note: for readability the code of
gsp
neglects sanity checks and also doesn't handle exceptions. Ifgit subtree push
fails your back to manual labour.