Basic GitHub tutorial for developers
Gitx and GitHub Tutorial for Beginners
Git is a version control system. It helps you track changes in your code over time. GitHub is a website where developers store and manage Git repositories online.
- save code history || see older codes >> work safely with other developers >> avoid overwriting each other’s code
Git File Status: When you work with files in Git, they usually appear in one of these states:
| Untracked | new file that Git is not tracking yet | Modified | tracked file has been changed | Staged | file is ready to be committed | Unmodified | no changes made since the last commit |
Step 1: Install Git on Windows
- Go to https://git-scm.com/downloads
- after install check version in cmd git --version
- Fir time Config git as
git config --global user.name "RIZWAN AKHTAR" git config --global user.email "[email protected]"
To view your saved Git configuration:
git config --list
USEFULL COMMANDS:
| 1 | git clone https://github.com/RizwanKMW/reviewsfunda.git |
git clone is used to clone the repositry from github to local, This command creates a copy of the project on your computer. |
| 2 | git status |
Mofied files, staged files (only that added using git add), not tracked files |
| 3 | git add |
to stage files, git add index.php , git add . (all changed files add to staging), |
| 4 | git commit |
add a message to staged files git commit -m "Add initial files" |
| 5 | git push |
send changes to github git push origin main >> push all code to main branch you can add other branches also |
| 6 | git branch |
Check branch name using git branch if want to rename it use git branch -M main |
Creating a New Git Repository from Scratch
If your project is only on your computer and not yet connected to GitHub, follow these steps.
| 1 | git init |
init This turns your folder into a Git repository. |
| 2 | git add . |
add all files to staging status |
| 3 | git commit -m "Add initial files" |
add a commit message to files |
| 4 | git remote add origin <repository-link> |
connect local project with github repository ie git remote add origin https://github.com/username/projectname.git |
How to clone private repositories to remote servers ie Github -> namecheap
- PuTTY installed, with plink.exe on your PATH.
- SSH access enabled on the Namecheap hosting plan.
- Git installed on the Namecheap server (already included on all Namecheap plans).
Logging into the server doesn't automatically grant it access to a private repo GitHub still needs to know who the server is.
Option 1: SSH deploy key (recommended)
1. In namecheap generate keys using below command
ssh-keygen -t ed25519 -C "server-deploy"
This creates two files: ~/.ssh/id_ed25519 , ~/.ssh/id_ed25519.pub
2. Copy the public keycat ~/.ssh/id_ed25519.pub
3.Goto below directory and paste the public keys there
GitHub → Settings → SSH and GPG Keys → New SSH Key
4. Goto namecheap terminal and paste below command
git clone [email protected]:USERNAME/REPOSITORY.git #this will clone zip source code
to clone direct files use below commands
cd ~/public_html
git init
git remote add origin [email protected]:USERNAME/REPOSITORY.git
git pull origin main
5. Deploy updates from GitHub
git pull origin main
Option 2: HTTPS + personal access token
git clone https://<username>:<token>@github.com/<user>/<repo>.git
deploy.bat
Set your own credentials at the top before using it.
https://raw.githubusercontent.com/RizwanKMW/github_deploy_script/refs/heads/main/deploy.bat
Understanding Branches
Branches let you work on features or fixes without affecting the main project immediately.
For example, if you want to create a new feature, you can create a branch for it. Once the feature is ready, you can merge it into the main branch.
See all branches
git branch
Switch to another branch
git checkout branch-name
Create and switch to a new branch
git checkout -b new-branch-name
Delete a branch
git branch -d branch-name
Merging Branches
After finishing work in a branch, you can merge it into your main branch.
Compare differences before merge
git diff branch-name
Merge a branch into your current branch
git merge branch-name
Example workflow:
- Create branch login-page
- Work on login feature
- Commit changes
- Switch to main
- Run git merge login-page
Pull Latest Changes from GitHub
If another developer updated the project, or if you updated code directly on GitHub, you should pull the latest changes.
git pull origin main
This downloads and merges the latest changes from GitHub into your local branch.
Delete Files or Folders in Git
If you want to remove a file or folder from the repository, use:
git rm file.txt
git rm -r folder-name
Then commit and push:
git commit -m "Remove unused files"
git push origin main
Undoing Changes
Beginners often make mistakes. That is normal. These commands help you undo common changes.
Discard changes in a file before staging
git checkout -- index.html
This restores the file to the last committed version.
Unstage a file after git add
git reset index.html
Undo last commit but keep changes
git reset --soft HEAD~1
Undo last commit and remove changes
git reset --hard HEAD~1
Warning: The hard reset command permanently removes changes that are not saved elsewhere.
Helpful Daily Git Workflow
Here is a simple daily routine for beginners:
- Open project folder
- Run git pull origin main
- Make your code changes
- Run git status
- Run git add .
- Run git commit -m "your message"
- Run git push origin main
Example Full Workflow
Here is a complete beginner example from start to finish:
git clone https://github.com/username/projectname.git
cd projectname
git status
git add .
git commit -m "Update homepage content"
git push origin main
How to Create a README.md File
A README.md file explains your project. It is usually the first file people read on GitHub.
Basic example:
# Project Name
## Description
Short details about the project.
## Features
- Login system
- Dashboard
- Contact form
## Installation
1. Clone the repository
2. Open the project
3. Run the project
## Author
Your name
Best Tips for Beginners
- run git status often
- write clear commit messages
- pull latest changes before starting work
- use branches for new features
- do not use git reset --hard unless you are sure
- practice with a test repository first
Common Mistakes Beginners Make
- forgetting to run git add before commit
- pushing to the wrong branch
- editing code without pulling latest updates
- using unclear commit messages like update files
- confusing Git with GitHub
Quick Command Summary
git --version
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
git config --list
git clone <repository-link>
git status
git add .
git add index.html
git commit -m "Your message"
git push origin main
git pull origin main
git init
git remote add origin <repository-link>
git branch
git branch -M main
git checkout branch-name
git checkout -b new-branch-name
git branch -d branch-name
git diff branch-name
git merge branch-name
git rm file.txt
git rm -r folder-name
git reset index.html
git reset --soft HEAD~1
git reset --hard HEAD~1
xd