Checkpoint #1, 04/07/2024 - My first 'DevOps' project - Part 1

Getting started with GitHub

I figured I'd try my hand at a basic project after learning the fundamentals of Bash scripting. The goal - make a basic tool that allows users to upload a file to the cloud via CLI (Command Line Interface). My first day mainly consisted of learning the basic ins and outs of Git, specifically how to create an online repository (a recommended process for DevOps). Here's what I attempted and accomplished, and learned in the process:

  • First, I changed the current directory to my desired project directory i.e. where the project files are located. This can be accomplished by the bash command

      cd CloudUploader/
    
  • Then, I initialized a git repository via the bash command

      git init
    
  • This adds a hidden .git file to enable 'tracking' of the git index

  • With the git initialized, I added all the files within the directory to the git index using the command

      git add --all
    
  • With the -all flag, all the files in the desired directory are added

  • Now, I had to configure the author identity with my user name using the command

      git config --global user.name "YashRalla"
    
  • The --global flag was used to set the identity outside this repo as well, user.email is another option

  • With that out of the way, it was time to commit my code to the repo using the command

      git commit -m 'Initial project commit'
    
  • The -m flag allows the user to add a message, given in single quotes (In my case, 'Initial project commit'

  • Alongside this, I added a remote using the command

      git remote add origin https://git@github.com/YashRalla/CloudUploader.git
    
  • Here I faced some confusion, originally I had tried with ssh instead of https, but I got the error given below

      ssh: Could not resolve hostname github.com: Name or service not known
    
  • Having created a remote that wouldn't serve my purpose, I first checked the status of the remote using

      git remote -v
    
  • And later deleted it using the command

      git remove origin
    
  • As seen when originally creating the remote, I had given it the name of 'origin', but remote names have to be unique. If I wanted to create a new remote with the same name, I had to delete the old one first} Having done so, I was now able to create a working remote using https

  • Now, time to actually push to GitHub. I used the command:

      git push -u -f origin master
    
  • This pushes the code to the branch master, in this case a separate branch from the main branch already present in the remote. The -u sets the remote as the default upstream, hence no need to specify the remote each time. -f forcibly overrides all files in the repo.

  • Yet another issue arose when I typed my GitHub password in after being prompted for it. Turns out, password authentication was removed on August 13, 2021, and I had gotten an error for the same in the shell. So now, I had to use a token wherever I was prompted for my password! That's a bit annoying. Anyway, I generated a token in GitHub by going into Account/Settings/Developer Settings/Personal Access Tokens/Tokens (classic)/Generate New Token (classic), where I had to make a note and define the scope. That's what I had to use in place of 'password'.

  • Anyway, after all of that, I was finally able to commit my code to the online repository, and confirmed the same by checking GitHub.

  • So that's how I got started with a GitHub repository. Next time, moving on to developing the tool.

Resources:

TL;DR:

I embarked on a project to create a CLI tool for uploading files to the cloud using Bash scripting. On the first day, I navigated Git basics, such as initializing a repository, adding files, configuring user identity, and committing code. I encountered issues with SSH and had to switch to HTTPS for creating a remote, which involved removing the faulty remote and setting up a new one. Additionally, I learned about GitHub's authentication changes and generated a personal access token to replace my password. Ultimately, I successfully pushed my initial commit to GitHub.