- Introduction
- Git Basics
- Git Commands
- GitHub Basics
- GitHub Commands
- Working with Remote Repositories
- Branching and Merging
- Common Errors and Fixes
- Useful Tips
- Git is a version control system for tracking changes in source code.
- GitHub is a cloud-based hosting platform for Git repositories to collaborate and share code.
- Tracks changes in source code.
- Used for collaboration on coding projects.
- Local operations, distributed system.
git --version # Check Git version
git config --global user.name "Your Name" # Set Git username
git config --global user.email "you@example.com" # Set Git emailgit init # Initialize a local Git repositorygit status # Check status
git add <filename> # Stage file
git add . # Stage all files
git commit -m "Commit message" # Commit changesgit log # Show commit logs
git log --oneline # One-line log formatgit rm <file> # Remove file
git mv <old> <new> # Rename file- Online platform to store repositories.
- Offers collaboration tools like Pull Requests, Issues, Wiki, Actions.
- Remote storage for Git repositories.
git remote add origin https://github.com/username/repo.git # Add remote repo
git remote -v # Verify remote URLgit push -u origin main # Push initial commit to GitHub
git pull origin main # Pull updates from GitHub
git push # Push changesgit clone https://github.com/username/repo.git # Clone repogit fetch # Download changes
git merge origin/main # Merge fetched changes
git pull # Fetch + merge in one commandgit branch # List branches
git branch <branch-name> # Create branch
git checkout <branch-name> # Switch to branch
git checkout -b <branch-name> # Create & switch to branchgit merge <branch-name> # Merge branch into currentgit branch -d <branch-name> # Delete branch locallyecho "# Your_Repository_Name" >> README.md # 1. Create a README file
git init # 2. Initialize Git
git add README.md # 3. Add Files to Staging Area
git commit -m "your commit message" # 4. Commit Changes
git branch -M main # 5. Rename the Branch to 'main'
git remote add origin https://github.com/your-username/your-repository.git # 6. Add Remote Repository
git push -u origin main # 7. Push Changes to GitHubgit remote add origin https://github.com/your-username/your-repository.git
git branch -M main
git push -u origin main| Error | Fix Command |
|---|---|
Updates were rejected because the remote contains work... |
git pull --rebase origin main |
fatal: refusing to merge unrelated histories |
git pull origin main --allow-unrelated-histories |
error: failed to push some refs to 'url' |
git pull --rebase origin main or fix conflicts, then git push |
| Mistaken commit message | git commit --amend |
| Push to wrong branch | git push origin <correct-branch> |
- Check Configurations
git config --list # List all configurations- Undo Last Commit (Keep Changes)
git reset --soft HEAD~1- Undo Last Commit (Remove Changes)
git reset --hard HEAD~1- Create .gitignore file to ignore specific files/folders.
git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin https://github.com/username/repo.git
git push -u origin mainMade with β€οΈ by Selvaneyas