
In this tutorial, we will try to cover all steps right from creating a local git repository to committing some code and pushing our first repo from local to GitHub remote repository.
Step 1: Check if git is installed on your System
The first step is to check if git is installed on your device. Open Command Line (CMD) if you Windows, or Terminal if you are using Linux/Mac and run the following command,
# git version
git version 2.36.2
You should get the git version back as a response, if you get git: not found, then you need to first install git on your device.
Installing Git:
Windows: https://code2care.org/howto/install-git-on-windows
Ubuntu/Linux: https://code2care.org/linux/install-git-on-ubuntu-linux
Mac: Run command: brew install git
Step 2: Creating local repository
Let us create a directory which we will use as a local git repo
# mkdir my-git-repo
# cd my-git-repo
Step 3: Initialize Local Git Repo
% git init
Initialized empty Git repository in /my-git-repo/.git/
✏️ Make sure that you change the directory to my-git-repo before executing the git init command.
Step 4: Create a file and add to staging area
Create a file index.html# echo "<h1>Hello World<h1>" > index.html
Add file to staging area
# git add index.html
Step 5: Commit the file to git
# git commit -m "First commit"
[main (root-commit) 11a3895] First Commit
1 file changed, 1 insertion(+)
create mode 100644 index.html
Step 6: Create a project on GitHub Account
Now login to your GitHub account and create a public or private repo named the same what we have locally my-git-repo
Step 7: Generate a Personal Access Token
1. Go to github.com,
2. Go to Profile -> Settings,
3. Select Developer Settings,
4. Select Personal access tokens,
5. Now click on Generate new token,
6. Select Expiration and Scope,
7. Click on Generate Token.
8. Copy the token, it should look something like this ghp_129ZVLCiqkYTiWXxYC9ZSXjf20AkhN1InLO
Step 8: Add Remote Repo to Git
# git remote add origin your-personal-access-token@github.com:your-github-user/my-git-repo.git
Step 9: Push Local Brach to GitHub Remote Branch
# git push origin -u main
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 231 bytes | 115.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/my-git-user/my-git-repo.git
* [new branch] main -> main
branch 'main' set up to track 'origin/main'.
✏️ You might have the default branch name as master instead of main

Facing issues? Have Questions? Post them here! I am happy to answer!
- Fix [oh-my-zsh] Cant update: not a git repository
- [fix] fatal: pathspec index.html did not match any files error
- How to ignore files in git using .gitignore file
- Git Fix: fatal: refusing to merge unrelated histories Error
- Install GitHub Command Line Tool on Mac
- How to change directory in Git bash
- Get List of all local branches git command
- fix fatal: --local can only be used inside a git repository error
- [git] fatal: your current branch 'main' does not have any commits yet
- Git Revision Questions Before the Interview
- Change the default git branch name from master to main
- git command to remove/unstage files from staging area
- Remove git config at Local, Global or System Levels?
- [fix] fatal: this operation must be run in a work tree in git
- Clone a particular remote brach using git clone command
- How do I get a list of all branches in Git?
- How to check your installed version of Git
- Step-by-Step: How to delete a git branch from local as well as remote origin
- Git Commit - Author identity unknown, Please tell me who you are email
- fatal: Unable to create '/c/git_repo/.git/index.lock': File exists. If no other git process is currently running, this probably means a git process crashed in this repository earlier.
- How to Rename a Git Local Branch Using the --move Option
- Perform an Empty Commit in Git without anything in Staging Area
- [Fixed] Git Clone git@github.com: Permission denied (publickey) Could not read from remote repository Fatal error
- GitHub: How to Search Code
- Rename git branch on Local and GitHub Remove using Command
- trurl: A new command-line tool for URL parsing and manipulation by cURL Developer - cURL
- Add Bookmark macOS Safari - MacOS
- Save TextEdit file as a PDF - MacOS
- Android : DeviceMonitor] Sending Tracking request failed! Error - Android
- How to install PowerShell on Mac using Brew - Powershell
- Create Nested Directories using Java Code - Java
- bash get year 2021 calendar - Bash
- Calculate Volume of Ellipsoid - C-Program