
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

Have Questions? Post them here!
- [Fixed] Git Clone git@github.com: Permission denied (publickey) Could not read from remote repository Fatal error
- Github: How to Invite Collaborators
- Git Commit - Author identity unknown, Please tell me who you are email
- [Solution] fatal: not a git repository (or any of the parent directories): .git
- [fix] zsh: command not found: git
- Github: fatal: Authentication failed Support for password was removed on August 13, 2021
- Get List of all local branches git command
- Git Revision Questions Before the Interview
- git fatal: Authentication failed error [fix]
- How to Install Git on Ubuntu Linux
- GitHub: How to Search Code
- How to change Git Default Author and Committer details in Eclipse
- How to check your installed version of Git
- Install GitHub Command Line Tool on Mac
- How to Merge Branch into Master Branch
- Perform an Empty Commit in Git without anything in Staging Area
- Git Fix: fatal: refusing to merge unrelated histories Error
- How to undo last Git Commit on Local Repository?
- git command to remove/unstage files from staging area
- Step-by-Step: Setting up Docker + Ubuntu Linux + Git + GitHub Tutorial
- Remove git config at Local, Global or System Levels?
- Fix [oh-my-zsh] Cant update: not a git repository
- Git Config Command - A Deep Dive
- 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 change directory in Git bash
- How to install Packages in Sublime Text Editor - Sublime-Text
- MySQL : Error :1000 SQLSTATE: HY000 (ER_HASHCHK) Message: hashchk Server Error - MySQL
- How to upload file programmatically to SharePoint Document Library using Server Object Model C# .Net - SharePoint
- Convert Java Array to ArrayList Code Example - Java
- Notepad++ Mark and Copy feature - NotepadPlusPlus
- List of Code Snippets/Templates to Eclipse IDE - Eclipse
- How to stop/start/restart apache server using command [Ubuntu] - Ubuntu
- Show Android Studio Emulator in a Separate Window - Android-Studio