Skip to main content

Clone and Push Source Code

To clone and push code to your self-hosted Gitea instance running on Kubernetes, you'll need to use the SSH service exposed by Gitea. Here's how to do it:

1. Setup SSH Access

First, ensure your SSH key is added to Gitea so that you can use it for Git operations (clone, push, etc.).

Steps to Add SSH Key in Gitea:

  1. Access the Gitea web interface at your custom domain.
  2. Log in to your Gitea account.
  3. Go to Settings > SSH Keys > Add Key.
  4. Paste your public SSH key in the provided field and save.

2. Clone a Repository

Once your SSH key is added, you can clone repositories using SSH.

  • Get the SSH URL for your repository:
    • Navigate to the repository in Gitea.
    • Click the Clone button.
    • Copy the SSH URL (e.g., [email protected]:username/repository.git).
  • Clone the repository: On your local machine, run:
git clone git@<domain>:username/repository.git

Replace username/repository.git with the actual repository path.

3. Push Code to the Repository

After cloning the repository, you can push your local changes to it.

1. Navigate to the cloned repository directory

cd repository

2. Make changes to your code and commit them:

git add .
git commit -m "Your commit message"

3. Push the changes to Gitea:

git push origin master

This will push your changes to the master branch (replace with the appropriate branch name if needed).

4. SSH Configuration (Optional)

If you want to avoid typing the full SSH URL every time, you can set up an SSH config file:

  1. Open or create the SSH config file:
nano ~/.ssh/config
  1. Add the following to it:
Host <domain>
  User git
  HostName <domain>
  Port 22
  IdentityFile ~/.ssh/id_rsa  # Path to your private key

Now you can clone and push using a shorter URL, like:

git clone git:username/repository.git

Accessing SSH via Kubernetes (if needed)

If you're accessing Gitea's SSH service through Kubernetes, ensure you're using the correct NodeIP and port, as exposed by the NodePort service:

  • The SSH port will be Node-IP:32222 (or the port you set in the service definition).