Hello, and have a nice day!

Tech: Connecting to Github via SSH and Creating an Alias

Connect to Github

Connecting to a GitHub repository via SSH involves a few steps to set up the SSH key and configure your GitHub account. Here's a step-by-step guide to help you with the process:

Generate an SSH Key: If you don't already have an SSH key, you'll need to generate one on your local machine. Open a terminal and run the following command, replacing your_email@example.com with your GitHub-associated email address:

ssh-keygen -t ed25519 -C "<your_email@example.com>"

You can also choose a different algorithm (-t) like rsa if you prefer.

Follow the prompts to save the key to the default location (usually ~/.ssh/id_ed25519 or ~/.ssh/id_rsa) and set an optional passphrase for added security.

Add SSH Key to SSH Agent (Optional but recommended): Running an SSH agent will allow you to manage your SSH keys more easily. Start the agent and add your key:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

Copy the Public Key: Display your public key so you can add it to your GitHub account:

cat ~/.ssh/id_ed25519.pub

Copy the entire output.

Add SSH Key to GitHub: Open your GitHub account settings. Go to Settings > SSH and GPG keys > New SSH Key. Paste your copied public key into the "Key" field and give it a recognizable title.

Test the SSH Connection: To test the connection, use the ssh -T command, followed by git@github.com. This command checks if your SSH key is correctly set up with GitHub:

ssh -T git@github.com

If prompted, type "yes" to add the GitHub host to your list of known hosts.

Configure Git: If you haven't configured your Git username and email, you should do so using these commands:

git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"

Clone a Repository: Now you're ready to clone a repository using SSH. Go to the repository you want to clone on GitHub and click the "Code" button. Make sure you select "SSH" and then copy the SSH URL. In your terminal, navigate to the directory where you want to clone the repository and run:

git clone git@github.com:username/repository.git

Replace username with the actual GitHub username and repository with the repository name.

You should now be able to interact with your GitHub repository using SSH. Remember, SSH offers a more secure way to connect to your repositories compared to HTTPS.

Creating an Alias to Automatize

You can create an alias in your ~/.bashrc file that simplifies the process of adding, committing, and pushing changes to a GitHub repository. Here's an example script for the alias:

Open your terminal.

Open your ~/.bashrc file using a text editor. For example:

nano ~/.bashrc

Add the following lines to the end of the file:

alias upload='git add . && git commit -m "Auto commit" && git push origin master'

This alias combines the git add ., git commit, and git push commands into a single upload command.

Save the file and exit the text editor.

Apply the changes by running:

source ~/.bashrc

Now you can use the upload command in your terminal to automatically add, commit, and push changes to your GitHub repository. Here's how you would use it:

Navigate to your repository's folder using the terminal.

Make changes to your files.

Run the upload command:

upload

#tech