Git Beginner Step-by-Step Commands
1. Initialize a new Git repository
git init
Creates a new local Git repository inside the folder.
2. Check repository status
git status
Shows tracked, untracked, staged, and modified files.
3. Add a single file to staging area
git add README.md
Prepares README.md for commit.
git add git-cheat-sheet-education.pdf
Adds PDF file to staging area.
5. Remove file from staging area only
git rm --cached git-cheat-sheet-education.pdf
Unstages the file but keeps it in the folder.
git commit -m "This is my First Commit"
Saves staged changes permanently in Git history.
7. Rename branch from master to main
git branch -M main
Changes default branch name to main.
git branch
Displays available branches and current branch.
9. Add remote GitHub repository
git remote add origin https://github.com/rpipaliya/practivcegit.git
Connects local repository with GitHub repository.
10. Verify remote repository
git remote -v
Shows fetch and push URLs of remote repository.
git push -u origin main
Uploads local commits to GitHub and sets upstream branch.
12. Configure Git username globally
git config --global user.name "Rushil Pipaliya"
Sets author name for all Git commits.
13. Configure Git email globally
git config --global user.email "rpipaliya@stud.hs-heilbronn.de "
Sets author email for all Git commits.
14. Add modified file again
git add README.md
git commit -m "This is my Second Commit"
Saves new changes in commit history.
16. Push latest changes to GitHub
git push origin main
Uploads latest commits to GitHub.
Check complete commit history
git log
Shows all commits with commit IDs.
Show short commit history
git log --oneline
Displays compact commit history.
Clone existing repository
git clone
Downloads repository from GitHub to local machine.
Pull latest changes from GitHub
git pull origin main
Downloads and updates latest changes from remote repository.
Show differences in files
git diff
Displays unstaged file changes.
git restore --staged
Removes file from staging area.
git rm
Removes file from Git and local folder.