a7d4e6ec0e0ad97c0ac025edb80b0cb72fca1d29
GetGit - Git Repository Setup Tool
A simple bash script that helps users set up SSH keys and clone repositories from a private git server.
Features
- SSH Key Generation: Automatically generates SSH keys if they don't exist
- Dynamic User Support: Works with any username on the git server
- Repository Discovery: Automatically discovers available repositories for the user
- Interactive Selection: Allows users to choose which repository to clone
- Dotfiles Support: Special handling for dotfiles repositories with automatic setup execution
Usage
-
Make the script executable:
chmod +x setup.sh -
Run the script:
./setup.sh -
Follow the prompts:
- Enter your git username
- Generate SSH key (if needed)
- Add the SSH key to your git account
- Select which repository to clone
How It Works
1. Username Input
The script prompts for your git username, which is used to:
- Discover available repositories
- Construct repository URLs
- Set up proper directory structure
2. SSH Key Management
- Checks for existing SSH key (
~/.ssh/id_ed25519) - Generates a new key if none exists
- Displays the public key for copying to your git account
3. Repository Discovery
The script discovers ALL accessible repositories through multiple methods:
Primary Method - API Access:
- Attempts to use GitLab/Gitea API to fetch all repositories you have access to
- Includes both owned and shared repositories
- Automatically detects read/write permissions
Fallback Method - Pattern Scanning:
- Scans your own repositories:
username/dotfiles,username/scripts, etc. - Checks common shared repositories from users like:
admin,shared,public,team,common,devops,infrastructure - Discovers additional project repositories:
website,api,frontend,backend,database,monitoring, etc. - Tests SSH access to determine if you have read access to each repository
Repository Types Discovered:
- Your repositories: All repos you own
- Shared repositories: Repos you have read/write access to
- Public repositories: Publicly accessible repos on the server
- Team repositories: Organization/team repos you're a member of
4. Repository Selection
Users can:
- Select from numbered list of all discovered repositories (owned and shared)
- Press Enter to use
username/dotfiles(if available) - Type
customto enter a custom repository path - See access type indicators:
(owner),(shared), etc.
5. Cloning and Setup
- Clones the selected repository to the appropriate directory
- For dotfiles repositories: runs
setup.shautomatically - For other repositories: simply clones to
~/repository-name
Configuration
The script can be configured by modifying the settings at the top:
### === SETTINGS === ###
GIT_SERVER="git.del-c.net" # Change to your git server
Directory Structure
- Dotfiles:
~/.dotfiles/ - Other repos:
~/repository-name/
Requirements
- Bash shell
- Git installed
- SSH client
- Access to the configured git server
Example Flow
$ ./setup.sh
[?] Enter your git username:
Username: john
[+] No SSH key found. Need to generate a new SSH key...
[+] If you are using the correct user, please enter your email for the SSH key.
Enter your email for the SSH key: john@example.com
[*] Add the following public key to your GitHub account:
----------------------------------------
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGx... john@example.com
----------------------------------------
Press Enter after you've added the key...
[+] Fetching all accessible git projects...
[*] Attempting to fetch repositories via API...
[*] Found repositories via API:
1. john/dotfiles (owner)
2. john/scripts (owner)
3. team/shared-configs (shared)
4. admin/common-tools (shared)
5. public/templates (shared)
[?] Which project would you like to download?
Enter the number of the repository from the list above, or:
- Press Enter to use john/dotfiles (if available)
- Type 'custom' to enter a custom repository path
Enter your choice: 3
[*] Selected repository: git@git.del-c.net:team/shared-configs.git
[*] Download directory: /Users/john/shared-configs
[+] Cloning selected repository...
[*] Repository cloned successfully to: /Users/john/shared-configs
Troubleshooting
SSH Key Issues
- Ensure the SSH key is added to your git account
- Check SSH connection:
ssh -T git@git.del-c.net
Repository Not Found
- Verify the repository exists on the server
- Check username spelling
- Ensure you have access to the repository
Permission Denied
- Confirm SSH key is properly added to git account
- Verify you have read access to the repository
Contributing
Feel free to submit issues and enhancement requests!
Description
A simple bash script that helps users set up SSH keys and clone repositories from a private git server.
Languages
Shell
100%