Very often I find myself working something on remote server, and wanting to have a remote .git repository of changes, but almost always I do not do it, because of the process of creating a new public key, adding it to the gitolite admin repository, ... A lot of steps.
Here is procedure on how to start .gitting as soon as possible, and once you have a 'free' time (usually near the end of the day), you can go through these steps in one sitting.
Important thing is to have it in .git as soon as possible. Thinking about permission, and public keys, we will left for later.
Here is the workflow.
User starts working on repository
cd project/ git init git add -A . git commit -m 'initial commit' git push --set-upstream email@example.com:test/this/is/my/repository master
You can now start working with your own repository:
- edit file(s)
- git add file(s)
- git commit -m 'message about the change'
- git push
Admin can review what new repositories are created
ssh firstname.lastname@example.org info test/
User can create new public key and start working privately on this repository
Give that user a key. A temporary key !
ssh-keygen # IMPORTANT: use password!!! cat ~/.ssh/id_rsa.pub # TODO - How to easily send a .pub key ? cp ~/.ssh/id_rsa.pub . git add id_rsa.pub git status git commit -m 'added .pub for current user' git status git push
Now, send the .pub key to the admin. If you follow steps above, you added .pub key to repository, and it will be available for admin.
Note: It is important that any temporary key have a password added to it. We will rotate these files, and do not want to have some key is there for someone else to use.
Admin, adding user's temporary key to the system
cd ~/git/gitolite/git.nedzadhrnjica.com/ cd keydir/nedzadhrnjica/temp/ mkdir remoteserver.com/ cp user.pub remoteserver.com/nedzadhrnjica.pub git add remoteserver.com/nedzadhrnjica.com git commit -m 'added temporary key for server remoteserver.com' git push
Admin, rename repository from temporary one into permanent/regular one
Clone test repository into real-one:
git clone email@example.com:test/this/is/my/repository git remote rename origin temp git remote add origin firstname.lastname@example.org:this/is/my/repository git config branch.master.remote origin git push
Remove test repository:
ssh email@example.com D unlock test/this/is/my/repository ssh firstname.lastname@example.org D rm test/this/is/my/repository
Additionally, you can create temporary repostiory with an information where the project is actually moved:
git clone email@example.com:test/this/is/my/repository git commit --allow-empty -m 'Repository moved to :this/is/my/repository' git push # Finally, remove local repository, since we do not need it anymore rm -fr repository/
This temporary repository will be left 'hanging' on the server, until all its users (actually only you) stop using it. You can easily remove it later on with steps listed previously.
User, update repository to the new one listed by admin
Once you sent the .pub key to admin, and admin added it to the repository, you can now replace user in
sed -ie 's/gitanon/git/' .git/config
And, continue working on your project.
When doing with .git repositories, always have all of them kept in the same local subdirectory:
This way, you will always have a list of all your repositories at one place, so you can easily review them, work on them, and improve them.
If you have projects in any other directories, you can always link from there to the git project into this subdirectory.
Make it a habit.
Do not even create 'temporary' .git repositories anywhere else. If you want to test something, create repository in ~/git/test/name and link this subdir to the place you are working with.
# create test repository git init ~/git/test/123 ln -s ~/git/test/123 123 cd 123/ # work on it vi notes.md git add notes.md git commit -m 'added notes.md' git push # finish testing, remove it cd .. rm 123/ # remote test repository, # or do it later, if you have not time now, or want to get back to it later again rm -fr ~/git/test/123/