I will be creating git repository for a website that I am creating now.
Prerequisites
- Download git in https://git-scm.com/downloads
- GitHub account created at github.com
Basic Git commands
- Initialize Git in a project: git init
- Check file status: git status
- Stage changes: git add .
- Commit changes: git commit -m "changes"
- Push code to GitHub: git push origin main
- View commit history: git log
- Create a new branch: git branch < branch name>
- Delete a branch: git branch -d <branch name>
- Switch to a branch: git checkout < branch
Steps
Initialize Git and configure username and email
- Go to the folder where you want to have version control.
grace@Mac React Full Stack % pwd /Users/grace/Documents/React Full Stack grace@Mac React Full Stack %
- Execute
git init. You will notice a.gitfile aftergrace@Mac React Full Stack % git init Initialized empty Git repository in /Users/grace/Documents/React Full Stack/.git/ grace@Mac React Full Stack % ls -al total 0 drwxr-xr-x@ 4 grace staff 128 Apr 13 18:50 . drwx------@ 69 grace staff 2208 Apr 12 21:58 .. drwxr-xr-x@ 9 grace staff 288 Apr 13 18:50 .git drwxr-xr-x@ 15 grace staff 480 Apr 12 22:02 front-end grace@Mac React Full Stack %
- First, check the initial configuration. If you don't set
user.nameanduser.email, Git will let you connect to GitHub, but when you try to commit it will give you a warning like:*** Please tell me who you are. Run git config --global user.email "you@example.com" git config --global user.name "Your Name" to set your account's default identity.✅ This is needed for commit identity. No connection to GitHub yet. Git needs your name and email to save inside the commit metadata!
- You can add the username and email using:
git config --global user.name johndoe git config --global user.email johndoe@youremail.com- Then recheck again in
git config --listorgit config --global --list
- Those configurations will be save to
~/.gitconfig. You can also use git config --list to check it.Checking config in ~/.gitconfig
[filter "lfs"] process = git-lfs filter-process required = true clean = git-lfs clean -- %f smudge = git-lfs smudge -- %f [user] name = johndoe email = johndoe@youremail.com "~/.gitconfig" 8L, 191B- Checking config using
git config --listgrace@Mac React Full Stack % git config --list credential.helper=osxkeychain init.defaultbranch=main filter.lfs.process=git-lfs filter-process filter.lfs.required=true filter.lfs.clean=git-lfs clean -- %f filter.lfs.smudge=git-lfs smudge -- %f user.name=johndoe user.email=johndoe@youremail.com core.repositoryformatversion=0 core.filemode=true core.bare=false core.logallrefupdates=true core.ignorecase=true core.precomposeunicode=true
Setup Github Token for Authentication
Since GitHub does not allow password login anymore for Git commands, you need a Personal Access Token.
- Go to GitHub → Settings → Developer Settings → Personal Access Tokens → Tokens (Classic).
- Click "Generate new token (classic)".
- Select scopes:
- ✅
repo - ✅
workflow - ✅
read:org
- ✅
- Generate and copy the token.
(Store it somewhere safe, you will only see it once!)


Creating repository remotely
- Install GitHub CLI (
gh)Mac (Homebrew):
brew install ghUbuntu Linux
sudo apt install gh- Windows: Download installer from https://cli.github.com/
Check if installed. You should see gh version output:
gh --version
Authenticate GitHub CLI using Personal Access Token
gh auth login- Select
GitHub.com - Select
HTTPS It will ask:
Authenticate Git with your GitHub credentials?
✅ Say
Yes- When asked about login:
- Choose Paste authentication token
- Paste your Personal Access Token you generated from GitHub.
✅ Now
ghis connected securely to your GitHub account.grace@Mac React Full Stack % gh --version gh version 2.54.0 (2024-07-31) https://github.com/cli/cli/releases/tag/v2.54.0 grace@Mac React Full Stack % gh auth login ? What account do you want to log into? GitHub.com ? What is your preferred protocol for Git operations on this host? HTTPS ? Authenticate Git with your GitHub credentials? Yes ? How would you like to authenticate GitHub CLI? Paste an authentication token Tip: you can generate a Personal Access Token here https://github.com/settings/tokens The minimum required scopes are 'repo', 'read:org', 'workflow'. ? Paste your authentication token: ****************************************

- Select
Create Remote GitHub Repository from Local Machine
Create a repo directly from your terminal
gh repo create react-blog --private --source=. --remote=origin --pushInternally, without using
ghcommand, this is the code it rungit remote add origin https://github.com/yourusername/my-blog.git git push -u origin main✅ But you didn’t need to type those yourself because the GitHub CLI (gh) did it automatically.
How to see it?
- using
git remote -vgrace@Mac React Full Stack % git remote -v origin https://github.com/grace188031/react-blog.git (fetch) origin https://github.com/grace188031/react-blog.git (push)✅ This confirms:
originis set- It points to your GitHub repository
- Git knows where to push and pull from
Summary
Action Old Manual Way New Way with ghCLISet remote manually git remote add origin <url>gh repo createauto does itPush manually git push -u origin maingh repo createcan push first commit too
Tried to execute the command but said no commit yet found. Hence, I will try to do my first commit first locally
grace@Mac React Full Stack % gh repo create react-blog --private --source=. --remote=origin --push `--push` enabled but no commits found in /Users/marygracezabala/Documents/React Full Stack grace@Mac React Full Stack % git add . grace@Mac React Full Stack % git commit -m "End of Chapter 1: Creating a React-Front-End" [main (root-commit) 12d2b4b] End of Chapter 1: Creating a React-Front-End 26 files changed, 3828 insertions(+) create mode 100644 front-end/.gitignore create mode 100644 front-end/README.md create mode 100644 front-end/eslint.config.js create mode 100644 front-end/index.html create mode 100644 front-end/package-lock.json create mode 100644 front-end/package.json create mode 100644 front-end/public/vite.svg create mode 100644 front-end/src/App.css create mode 100644 front-end/src/App.tsx create mode 100644 front-end/src/ArticlesList.tsx create mode 100644 front-end/src/Layout.tsx create mode 100644 front-end/src/NavBar.tsx create mode 100644 front-end/src/article-content.tsx create mode 100644 front-end/src/assets/react.svg create mode 100644 front-end/src/index.css create mode 100644 front-end/src/main.tsx create mode 100644 front-end/src/pages/AboutPage.tsx create mode 100644 front-end/src/pages/ArticlePage.tsx create mode 100644 front-end/src/pages/ArticlesListPage.tsx create mode 100644 front-end/src/pages/HomePage.tsx create mode 100644 front-end/src/pages/NotFoundPage.tsx create mode 100644 front-end/src/vite-env.d.ts create mode 100644 front-end/tsconfig.app.json create mode 100644 front-end/tsconfig.json create mode 100644 front-end/tsconfig.node.json create mode 100644 front-end/vite.config.ts grace@Mac React Full Stack % grace@Mac React Full Stack % gh repo create react-blog --private --source=. --remote=origin --push ✓ Created repository grace188031/react-blog on GitHub https://github.com/grace188031/react-blog ✓ Added remote https://github.com/grace188031/react-blog.git Enumerating objects: 33, done. Counting objects: 100% (33/33), done. Delta compression using up to 12 threads Compressing objects: 100% (29/29), done. Writing objects: 100% (33/33), 35.61 KiB | 11.87 MiB/s, done. Total 33 (delta 1), reused 0 (delta 0), pack-reused 0 remote: Resolving deltas: 100% (1/1), done. To https://github.com/grace188031/react-blog.git * [new branch] HEAD -> main branch 'main' set up to track 'origin/main'. ✓ Pushed commits to https://github.com/grace188031/react-blog.git marygracezabala@Mac React Full Stack %I successfully created my remote repository. Initially, this is private while we I am developing sample react blog site
Explanation:
my-blog→ your GitHub repo name--private→ or use--public--source=.→ current folder--remote=origin→ set remote nameorigin--push→ push immediately after creating

- Summary of commands
# Configure Git identity
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
# Authenticate GitHub CLI
gh auth login
# Create project
mkdir my-blog && cd my-blog
git init
# Create remote repo and push
gh repo create my-blog --private --source=. --remote=origin --push
# Normal Git work
echo "# My Blog" > README.md
git add .
git commit -m "First commit"
git pushCreate another branch locally
I want to separate my learningsper Chapter. Hence I will create another branch named Chapter 1
Create and switch to a new branch locally
grace@Mac React Full Stack % git checkout -b chapter-1 Switched to a new branch 'chapter-1'✅ This creates a branch called
chapter-1and moves you to it.(You can check you're on the right branch anytime with:)
grace@Mac React Full Stack % git branch * chapter-1 main(
*means you're currently onchapter-1.)I will add Chapter1.md in my chapter-1 branch
grace@Mac React Full Stack % git branch * chapter-1 main grace@Mac React Full Stack % echo "Chapter 1: Creating a React-Front-End" > chapter1.md grace@Mac React Full Stack % git add chapter1.md grace@Mac React Full Stack % git commit -m "Add Chapter 1 read me content" [chapter-1 aded723] Add Chapter 1 read me content 1 file changed, 1 insertion(+) create mode 100644 chapter1.mdPush the
chapter-1branch to GitHubgrace@Mac React Full Stack % git push -u origin chapter-1 Enumerating objects: 4, done. Counting objects: 100% (4/4), done. Delta compression using up to 12 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 335 bytes | 335.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 remote: remote: Create a pull request for 'chapter-1' on GitHub by visiting: remote: https://github.com/grace188031/react-blog/pull/new/chapter-1 remote: To https://github.com/grace188031/react-blog.git * [new branch] chapter-1 -> chapter-1 branch 'chapter-1' set up to track 'origin/chapter-1'.Explanation:
push→ uploads your branch-u→ sets upstream, so futuregit pushorgit pullwill automatically know you meanorigin/chapter-1origin→ your GitHub remotechapter-1→ branch name
- Summary of commands
git checkout -b chapter-1
git add .
git commit -m "Work on Chapter 1"
git push -u origin chapter-1
Creating branch chapter1-basic-css-design, Edit, Commit then Push
Create and switch to new branch
git checkout -b chapter1-basic-css-designDelete the chapter1.md and create a file chapter1-css.md
grace@Mac React Full Stack % git branch chapter-1 * chapter1-basic-css-design main grace@Mac React Full Stack % rm chapter1.md grace@Mac React Full Stack % echo "# Chapter 1: Basic CSS Design In this chapter, we introduce basic CSS concepts: - Styling text - Adding background colors - Adjusting margins and padding " > chapter1-css.md grace@Mac React Full Stack %Now stage the chapter1-css for commit
grace@Mac React Full Stack % git add chapter1-css.md chapter1.md grace@Mac React Full Stack % git status On branch chapter1-basic-css-design Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: chapter1-css.md deleted: chapter1.md grace@Mac React Full Stack % git commit -m "Add Chapter 1 Basic CSS Design content" [chapter1-basic-css-design 2ff32ca] Add Chapter 1 Basic CSS Design content 1 file changed, 7 insertions(+), 1 deletion(-) create mode 100644 chapter1-css.md delete mode 100644 chapter1.md marygracezabala@Mac React Full Stack %Push the branch to Github
marygracezabala@Mac React Full Stack % git push -u origin chapter1-basic-css-design Enumerating objects: 4, done. Counting objects: 100% (4/4), done. Delta compression using up to 12 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 459 bytes | 459.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 remote: remote: Create a pull request for 'chapter1-basic-css-design' on GitHub by visiting: remote: https://github.com/grace188031/react-blog/pull/new/chapter1-basic-css-design remote: To https://github.com/grace188031/react-blog.git * [new branch] chapter1-basic-css-design -> chapter1-basic-css-design branch 'chapter1-basic-css-design' set up to track 'origin/chapter1-basic-css-designSummary
git checkout -b chapter1-basic-css-design # (edit or create chapter1.md file) git add chapter1-css.md chapter1.md git commit -m "Add Chapter 1 Basic CSS Design content" git push -u origin chapter1-basic-css-design
Using Git Diff to differentiate two branches
Here is an example
grace@Mac React Full Stack % git diff chapter-1 chapter1-basic-css-design diff --git a/chapter1-css.md b/chapter1-css.md new file mode 100644 index 0000000..032def8 --- /dev/null +++ b/chapter1-css.md @@ -0,0 +1,7 @@ +# Chapter 1: Basic CSS Design + +In this chapter, we introduce basic CSS concepts: +- Styling text +- Adding background colors +- Adjusting margins and padding + diff --git a/chapter1.md b/chapter1.md deleted file mode 100644 index 8b53f46..0000000 --- a/chapter1.md +++ /dev/null @@ -1 +0,0 @@ -Chapter 1: Creating a React-Front-EndNow for example, you already execute
git add .(adds all files you added or modified) and you want to see the changes first before committing, you can executegit diff --staged. Please see example belowgrace@Mac React Full Stack % git diff --staged grace@Mac React Full Stack % git add . grace@Mac React Full Stack % git diff --staged diff --git a/front-end/src/App.css b/front-end/src/App.css index b9d355d..6081cc6 100644 --- a/front-end/src/App.css +++ b/front-end/src/App.css @@ -1,42 +1,5 @@ #root { - max-width: 1280px; + max-width: 800px; margin: 0 auto; padding: 2rem; - text-align: center; -} - -.logo { - height: 6em; - padding: 1.5em; - will-change: filter;- Here are useful commands you can use
Command What it shows
git diff Changes not yet staged (not added)
git diff --staged or git diff --cached Changes that are staged (already added but not yet commited)
git diff main chapter1-basic-css-design Differences between two branches
git diff HEAD Difference between current files and latest commit
No Comments