Manage, create, clone, pull, push multiple git repos from the command line.
If you love git and work daily with multiple git repos (even hubs) then
you will really want to use some kind of power git
utility commands
like these. I'm sure there are more out there. It was just faster to write
these than search.
Make sure you have ssh keys setup and grab the usual way:
cd ~
git clone http://github.com/robmuh/powergit.git
export PATH=$HOME/powergit/bin:$PATH
That just may be the only one you have to write out. The rest you can
put into a giturls
file, usually ~/.giturls
or ~/config/giturls
:
[email protected]:robmuh/config.git
[email protected]:robmuh/bin.git
[email protected]:robmuh/vimfiles.git
[email protected]:robmuh/mdaddlinks.git
[email protected]:robmuh/fmt.git
[email protected]:robmuh/filters.git
[email protected]:trainemon/trainemon.git
[email protected]:blockhead-battles/blockhead-battles.git
[email protected]:robmuh/robmuh.github.io.git com
git@main:robmuh/private.git
The second field is the directory in case you don't want the long name, but you knew that:
[email protected]:robmuh/robmuh.github.io.git com
Put something like the following in your bashrc
. (Here's mine with
more stuff in it.)
export GITURLS=$HOME/config/giturls
gcd () {
cd `gls $1 | perl -e '@m=split(/\s+/,<STDIN>);print$m[1]'`
}
Now you can grab all the rest with one command, but first let's make sure we got them all right:
gping
OK, looks good:
---------------------- [email protected]:robmuh/config.git ----------------------
dc8d8145850dad35e27a98760bd552d98f556b3f HEAD
----------------------- [email protected]:robmuh/bin.git ------------------------
581d2e5371a6f061aea8965042ee24d6fdb58d95 HEAD
--------------------- [email protected]:robmuh/vimfiles.git ---------------------
bb67c4d05af8d273fc863964b5ecb9b0e445e690 HEAD
-------------------- [email protected]:robmuh/mdaddlinks.git --------------------
4bd36c036947e7afc9791d4fae6df29e091e9041 HEAD
----------------------- [email protected]:robmuh/fmt.git ------------------------
7658ccae1f3434b385144510d06aeaef2e28b496 HEAD
--------------------- [email protected]:robmuh/filters.git ----------------------
b131133108e9c8b2655f4de49302e67bca5827e3 HEAD
----------------------- [email protected]:robmuh/note.git -----------------------
2b3fef7106ab99caacb217ae764e3f7b0e18b262 HEAD
----------------- [email protected]:robmuh/robmuh.github.io.git -----------------
8096e41b057f5b5a81352392e86e2a7defad652b HEAD
------------------- [email protected]:trainemon/trainemon.git -------------------
b81b2c76fac466c48ec4a72b0f800453fe7af2e4 HEAD
----------- [email protected]:blockhead-battles/blockhead-battles.git -----------
9e64af0d9c6c47ec7a387649a61cf7282be879c4 HEAD
----------- git@main:robmuh/private.git -----------
9999999999999999999999999999999999999999 HEAD
So can go ahead and clone them down:
gclone
The rest of the commands are pretty obvious:
save
- short forgit status; git add .; git commit ..., git push
gsave
- same assave
, but for all reposgls
- lists all your reposgls name
- lists all your repo namesgls url
- lists all your repo urlsgls dir
- lists all your repo directory full pathsgcd KEY
- changes to the first repo containing theKEY
in namegstatus
-git status
on all reposgpull
-git pull
every repo listed in$GITURLS
filegpush
-git push
every repo listed in$GITURLS
filegclone
-git clone
every repo listed in$GITURLS
filegurls
- opens the$GITURLS
file with your$EDITOR
gcmd CMD
-cd
into each repo and executeCMD
gfor GITCMD
-cd
into each repo and executegit GITCMD
gping
-git -ls-remote REPO HEAD
on eachREPO
Like I said, nothing fancy, just convenient. After using this I have completely dropped DropBox and other methods of saving files of any type other than media. The tools particularly help when moving stuff around between repos and reorganizing things.
Q: Did you know there is another powergit
project?
A: Yes, and I imagine there are a lot of them. Um, does anyone still use powershell anymore? ;P
Q: Aren't you afraid a command like 'save' will conflict?
A: No. There is no other 'save' in my world (nor in many other power users world). Git reigns.
Q: What about the overly simplistic 'save' comment and all the commits?
A: If you have a special save make sure you add a comment. Both the 'gsave' and 'save' commands take one. In fact, this allows you to make ONE comment on multiple repo commits at the same time from one command.
Q: Why isn't there a gcreate
or ginit
?
A: There was. Then I deleted it. In order for git push -u origin master
to work you have to first have a repo there. It's just easier
to create it on your hub of choice and gclone
(after adding to
.giturls
or git clone
it down.
Q: Why not just use bash
functions and aliases?
A: Fair question. Bash functions would be faster for sure. Mostly because I don't always have the luxury of using Bash, but strangely I usually find Perl on older and more edge-case OSes (AIX, Sun, HP-UX)