Setting up GitHub / Git on your Local Machine

Play this article
  1. First, you'll need to install Git on your local machine. Git is a version control system that enables you to track changes to your code and collaborate with other developers. You can download Git from the official website (git-scm.com) or use a package manager like Homebrew (for macOS) or apt-get (for Linux).

  2. Once Git is installed, you'll need to create a GitHub account if you don't already have one. You can create an account at github.com.

  3. Next, you'll need to generate a SSH key. This will allow you to authenticate with GitHub and push code to your repositories. To generate a SSH key, open a terminal window and enter the following command:

ssh-keygen -t rsa -b 4096

This will create a new SSH key and prompt you to enter a file to save the key in. You can just press Enter to use the default file location. You'll also be asked to enter a passphrase (you can leave this blank if you want).

  1. After generating the SSH key, you'll need to add it to your GitHub account. To do this, open the terminal window and enter the following command:
cat ~/.ssh/id_rsa.pub

This will display your SSH key. Copy the key to your clipboard.

  1. Go to the "Settings" page of your GitHub account and click on the "SSH and GPG keys" tab. Click on the "New SSH key" button and paste your SSH key into the "Key" field. Give the key a descriptive title (e.g. "My laptop") and click on the "Add SSH key" button.

  2. Now that you have your SSH key set up, you can clone a repository from GitHub to your local machine. To do this, go to the repository page on GitHub and click on the "Clone or download" button. This will display the repository's clone URL.

  3. In the terminal, navigate to the directory where you want to clone the repository and enter the following command:

git clone [repository-url]

Replace [repository-url] with the clone URL you copied from GitHub. This will create a new directory with the same name as the repository and download all the files into it.

  1. You can now make changes to the code in your local repository and use Git to track and commit your changes. To commit your changes, use the following commands:
git add [file] git commit -m "Commit message"

Replace [file] with the name of the file you want to commit, and "Commit message" with a brief description of your changes.

  1. To push your changes to the remote repository on GitHub, use the following command:
git push origin master

This will push your changes to the "master" branch of the repository.

That's it! You should now have a working copy of the repository on your local machine and be able to use Git and GitHub to collaborate with other developers.

Did you find this article valuable?

Support Edwin Valerio by becoming a sponsor. Any amount is appreciated!