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
.bashrcand append the following lineThen open a new (git-)bash and the alias
gspshould 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-subtreeonly 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-logof 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.
.gitsubtreesalongside 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
.gitsubtreesdoes not exist,gspwon't do anything otherwise it will print the command it executes and the corresponding output.Note: for readability the code of
gspneglects sanity checks and also doesn't handle exceptions. Ifgit subtree pushfails your back to manual labour.