Nicole Shoblom
email

Git Basics for a Personal Website

April 8, 2025 | Seoul, South Korea

When using Git I always think of the song "Kick, Push" by Lupe Fiasco, but in this post we will git push ;). If you want to make a personal website while getting some front end coding skills, learning Git is essential. So let's get started! First sign up to make a free account with Github. Git can be used without a Github account, but for building a personal website from scratch (i.e., without Wix, Wordpress, Squarespace, etc.) it's absolutely necessary. Additionally, pushing your work to a remote Github server acts as a backup in case anything should happen to you local computer! Next you will need to install Git on your computer, which is also free. Unfortunately for Windows users, this is where my post will be more helpful for Mac users. If on Windows or Linux please refer here for more instructions. So, if you have a Mac, I recommend installing Git via Homebrew, which is also free and also requires installation. To install Homebrew first search for the Terminal application and open a Terminal window. You will see a command prompt that looks like this.


nicole@Nicoles-MacBook-Pro ~ %

If you haven't installed Homebrew yet, you can run the following command after the command prompt to do so.

nicole@Nicoles-MacBook-Pro ~ % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

The installer will list what will be installed and the new folders that will be created. Follow the prompt to press RETURN/ENTER to continue. Then after successful installation you'll see "Next steps" commands to add Homebrew to your PATH. Copy and paste the commands directly into your terminal. Now installation of Git is easy by running the following command.

brew install git

You can verify that Git installed by running git --version, and you should see something like git version 2.39.5. If you made it this far you've won half the Git battle. Now let's do a toy example to give you an idea of how Git works. First, set up a global author name and email in Git by running the following commands. Replace "Your Name" and "Your Email" with your own name and email.

git config --global user.name "Your Name"
git config --global user.email "Your Email"

Next, search for the Finder app, open a new Finder window and create a new folder in Documents. Name the folder 'test'. Now in your Terminal window, enter the command cd, which stands for "change directory", to the folder you just made. For me it looks like:

cd /Users/nicole/Documents/test

The command prompt should now show your folder. For example, my command prompt now shows "test" at the end.

nicole@Nicoles-MacBook-Pro test %

Next initialize the folder as a git repository by running:

nicole@Nicoles-MacBook-Pro test % git init

If you get a message that "Terminal" would like to access files in your Documents folder, click OK. Open the test folder in Finder and on your keyboard hit ⌘ command + ⇧ shift + .. You should see a .git folder. Now create a README file and .gitignore file in your test folder by running the following commands in your terminal.

echo "# Test project" > README.md
touch .gitignore

Creating these files are Git best practices. The README.md file typically describes the repo and how others can get started with the repo. The .gitignore file is where you can list folders or files that you don't want Git to track. Check that the README.md and .gitignore files are in your folder in Finder. Now stage and commit all the changes you've made to the "test" folder by running the following commands.

git add .
git commit -m "Initial commit"

Next make sure you are logged into to your Github account and go to github.com/new to create a new repository. Give the repository the same name as the folder you just created. Set the repository to be "Public", and make sure "Add a README file" is not checked, and that both ".gitignore template" and "License" are set to None. Then click "Create repository", which will redirect you to your newly created repository page. Scroll down to "...or push an existing repository from the command line" to see the commands that will sync your local folder with the remote Github repository. For me I am instructed to run:

git remote add origin https://github.com/lupefiasco42/test.git
git branch -M main
git push -u origin main

(Yes, I made a new github account with username, lupefiasco42, just for those post 😂) You will then be prompted for your Github username and password. Go ahead and input your Github username. You will then be prompted for your password. However, in August 2021 Github now requires you to input a Github personal access token for your password. To get your personal access token go to github.com. Click on your profile photo in the top right hand corner, and select "Settings". Then in the left menu click on "Developer Settings". In the left menu of Developer Settings click on "Personal access tokens" and choose "Tokens (classic)". Click on "Generate new token" and choose "Generate new token (classic)". Provide a name for the token under Note, keep the default expiration date, and select all scopes. Then hit "Generate token", and copy the generated token. Go back to your terminal and paste the token in as the response to the password prompt. If you made it this far, then you've done your first git push! Congrats! You can now go back to Github.com and see that README.md and .gitignore show up on the repository page. Now let's make a change to README.md by opening it in Mac's TextEdit application on your local computer. In TextEdit make a new line that says anything you want. I wrote "This is a toy example". Save the file with your new change and then close it. Now in your terminal you can run git status and you should see that your "README.md" file is listed under "Changes not staged for commit". So let's stage, commit, and push our recent changes to the remote github repo.

git add .
git commit -m "Update readme"
git push

Note that git add . stages all modified or new files in your local git folder, but you can choose to stage only certain files. You can now refresh the Github.com repo page and see that README.md on the remote repo has been updated. OK, let's make some more changes to README.md. Reopen README.md in TextEdit, and add a dollar sign after every word in the sentence you made previously, then save and close the file. The second line in my readme file looks like this now: "This $ is $ a $ toy $ example $". Now let's pretend you've decided you don't want to have these dollar signs, and it would be too cumbersome to remove them one by one. Whatever can you do??? Git to the rescue! Run the following command in your terminal.

git checkout -- README.md

Reopen the README.md file to see that all the dollar signs are gone because the previous command reverted the readme file to the version you pushed with your last commit. To my readers - if you can stage, commit, push, and revert using Git, then you've taken a big step to building your personal website from scratch. Muchas gracias for reading my post and I hope it was helpful. Feel free to email me if you run into any trouble. Also, please stay tuned for sequential posts on using Visual Studio Code, Astro web framework, and Github Pages all for the purposes of building a personal website. 잘가요! Goodbye!