The Definitive Beginner Git and GitHub Guide for Personal Use

Daniel Park
8 min readAug 15, 2023

--

Using Git and GitHub for Beginners! Source: DEV Community

In the world of software, version control is the most important skill a developer can have. Since it is the system of collaboration, developers both junior and developer are expected to understand how individuals or teams can track modifications to their code, collaborate on projects, and maintain a history of changes.

However the problem with a lot of beginners when trying to get into version control is, where do you even start? Therefore, I wrote this quick guide to simplify Git and GitHub and how you can get started!

Using Git and especially the command line can be pretty daunting, but trust me once you learn, it’s as easy and highly applicable in the real world! Photo by Gabriel Heinzer on Unsplash

Whether you’re working solo or as part of a team, learning Git offers numerous benefits that can enhance your development workflow, improve your skills in the command line, and most importantly, help you organize your projects to show off to recruiters!

Part I. Configuring Git and GitHub

Step 0: Create a GitHub Account

Before we begin, make sure you have a GitHub account! Although there are other version control sites such as GitLab and Bitbucket (which is what I used during my time at JP Morgan), GitHub is currently the most popular repository site with many famous open source projects such as OpenAI and React!

If you don’t have one, you can sign up for one at https://github.com/. (Don’t worry, it’s free!)

GitHub, the world’s most popular development platform. Photo by Mohammad Rahmani on Unsplash

Step 1: Install Git

Git usually comes preinstalled in some Macs and Linux-based systems, but you can check if you have Git on your machine by typing git version in your terminal.

If not, you can visit the official Git website at https://git-scm.com/ and download the appropriate version for your operating system (Windows, macOS, or Linux).

Git’s Download Page (I’m currently on Linux) Source: git-scm

Step 2: Configure Git

  1. Open a terminal window. (Command Prompt on Windows, Terminal on Mac and Linux)
  2. Set your name and email address using the following commands (replace with your actual name and email):
$ git config --global user.name "Your Name"
$ git config --global user.email "your_email@example.com"

This is important because Git uses this information to connect yourself to every commit you make. Now no one else can claim your commits!

3. Change your default branch name to main. As of October 2020, GitHub has started to gradually rename the default branches of repositories from master to main. You can read more about it from GitHub here.

$ git config --global init.defaultBranch main

4. Optionally, you can configure the default text editor that will be used when Git needs you to type in a message. If not configured, Git will use your system’s default editor.

For example, if you wanted to use a text editor like Vim:

git config --global core.editor vim

However on a Windows system, if you wanted to use a different text editor, you have to specify the full path to the program.

For example, if you wanted to use NotePad++:

$ git config --global core.editor "'C:\Program Files\Notepad\notepad.exe' -multiInst -notabbar -nosession -noPlugin"

However, I’d recommend using good old Notepad for Windows 64-systems since the command is easy and consistent by system.

$ git config core.editor notepad

You can view more information on commit editor commands here.

5. Finally, if you want to check your Git configuration settings, you can list all the settings Git can find at that point with the following command

$ git config --list

Step 3: Generate a new SSH Key

As of August 2021, GitHub started requiring Token authentication (or SSH key) for all authenticated Git operations including access and writing data in repositories.

For some brief context on SSHs, SSH (Secure Shell Protocol) allows you to authenticate using a private key file on your local machine rather than the old way (HTTPS) that requires you to type in your username and password for every authentication. In the context of GitHub, you will generate a new private SSH key and add it to the SSH agent which will allow you to use your account on GitHub before you use the key to authenticate or sign commits.

You can read more on SSHs here.

But on the note of actionable steps:

  1. Open a terminal window. (Command Prompt on Windows, Terminal on Mac and Linux)
  2. Generate a new SSH key with the following command (replace with your actual email)
$ ssh-keygen -t ed25519 -C "your_email@example.com"

This creates a new SSH key, using the provided email as a label, and then you will be prompted to “Enter a file in which to save the key”, which you can press Enter to accept the default file location (unless you want to change the location)

> Generating public/private ALGORITHM key pair.
> Enter a file in which to save the key (/home/YOU/.ssh/ALGORITHM):[Press enter]

Next, you will be prompted to type a secure passphrase (click Enter if you wish to not have a passphrase)

> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]

Step 4: Adding SSH Key to the ssh-agent

  1. Check to see if you have existing SSH keys before adding a new SSH key to the ssh-agent. (This may be unnecessary if you have never done this before)
$ eval "$(ssh-agent -s)"
> Agent pid 59566

2. Add your SSH private key to the ssh-agent. If you are adding an existing key with a different name, replace id_ed25519 in the command with your key file name.

$ ssh-add ~/.ssh/id_ed25519

Step 5: Adding SSH Key to your GitHub Account

  1. Copy the SSH public key to your clipboard. Assuming your key file name is id_ed25519 (otherwise feel free to change it), this will display the key and you will need to copy it to your clipboard for pasting onto GitHub
$ cat ~/.ssh/id_ed25519.pub
# The key will output below on the terminal
# Copy the contents of the id_ed25519.pub file to your clipboard

2. Go to this link here to access your SSH and GPG keys. Or alternatively, you can click your profile picture on the top right corner of any page on GitHub, select Settings, and under Access select SSH and GPG keys.

3. Click New SSH Key

4. In the “Title” field, add a label for your key. (e.g. “My Laptop”)

5. For the “Key Type” option, select “authentication” key. (If you want more information on signiture types, go here.)

6. In the “Key” field, paste your public key and click Add SSH Key. If you are prompted, confirm SSH access to your account on GitHub.

Step 6: Verify SSH Connection to GitHub

Now that you have added your public key to your GitHub account, you can test the connection by attempting to SSH into GitHub.

To test the connection:

  1. Open a terminal window. (Command Prompt on Windows, Terminal on Mac and Linux)
  2. Use the ssh command followed by your GitHub username and the hostname github.com.
$ ssh -T your_email@example.com

3. If this is the first time you are connecting to GitHub via SSH from your local machine, you may see a message similar to the following:

> The authenticity of host 'github.com (IP_ADDRESS)' can't be established.
> RSA key fingerprint is SHA256:XXXXXX.
> Are you sure you want to continue connecting (yes/no)?

Verify that the key fingerprint matches GitHub’s key fingerprint (you can find GitHub’s key fingerprints on their website here). If they match, type yes to proceed.

If you receive the “successfully authenticated” message, your SSH connection to GitHub is working properly. This means that you can now use your SSH key for interactions with GitHub, such as pushing and pulling code repositories.

If your SSH key is set up correctly, you will see a message like:

Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.

Congratulations, you have successfully configured an SSH key with GitHub! You can start using GitHub to upload your projects!

Part II. Upload Projects onto GitHub

Now that you have Git configured with your GitHub account, you can begin uploading your projects! To do so:

  1. Open a terminal window. (Command Prompt on Windows, Terminal on Mac and Linux)
  2. Navigate to your project (using command line navigation commands)
  3. Initialize a Local Git Repository in the directory
git init

4. Create or add files to your project directory. ( git add . is NOT recommended since you may unintentionally add private files such as IDA keys, so here is your formal warning in doing so!)

git add .
git commit -m "Initial commit"

5. Create a New GitHub Repository

5.1. Log into your GitHub account

5.2. Click the “+” icon in the top right corner of your screen and select “New Repository”

5.3. Enter a repository name, description, and choose other settings

5.4. Click “Create Repository.”

Your Screen should look like this when creating a new project!

7. Connect Local Repository to GitHub by copying the repository’s URL from the repository page

Your URL is the one in the blue box under “Quick setup”!

8. Back in your terminal, link your local repository to the remote GitHub repository using the link from your repository page

git remote add origin <repository-url>

9. Push your local changes to GitHub!

git push -u origin main

Your repository should now be populated with your project!

Before you know it, you’re off using Git and GitHub! Feel free to add your existing projects and while you’re there, follow me on GitHub as well ;)

As you continue your journey, you’ll discover more advanced features and techniques that will empower you to become a proficient developer and contributor in the software development community. If you want to get more advanced with Git commands such as branching strategies and tagging, you may view them here.

Happy coding!

Sources

--

--

Daniel Park

"The best way to learn is to teach" - Frank Oppenheimer