Skip to content

selvaneyas/GitHub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“˜ Git & GitHub Complete Notes

πŸ“‘ Table of Contents


πŸ”° Introduction

  • 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.

πŸ”΅ Git Basics

  • Tracks changes in source code.
  • Used for collaboration on coding projects.
  • Local operations, distributed system.

πŸ’» Git Commands

βœ… Basic Git Setup

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 email

βœ… Initialize Repository

git init                         # Initialize a local Git repository

βœ… Basic Workflow

git status                       # Check status
git add <filename>               # Stage file
git add .                        # Stage all files
git commit -m "Commit message"   # Commit changes

βœ… View Logs & History

git log                          # Show commit logs
git log --oneline                # One-line log format

βœ… File Operations

git rm <file>                    # Remove file
git mv <old> <new>               # Rename file

🟣 GitHub Basics

  • Online platform to store repositories.
  • Offers collaboration tools like Pull Requests, Issues, Wiki, Actions.
  • Remote storage for Git repositories.

🟒 GitHub Commands

βœ… Connecting Local Repo to GitHub

git remote add origin https://github.com/username/repo.git  # Add remote repo
git remote -v                      # Verify remote URL

βœ… Pushing and Pulling

git push -u origin main             # Push initial commit to GitHub
git pull origin main               # Pull updates from GitHub
git push                           # Push changes

🌐 Working with Remote Repositories

βœ… Clone Repositories

git clone https://github.com/username/repo.git  # Clone repo

βœ… Fetch & Merge Changes

git fetch                           # Download changes
git merge origin/main               # Merge fetched changes
git pull                            # Fetch + merge in one command

🌿 Branching and Merging

βœ… Branch Operations

git branch                          # List branches
git branch <branch-name>            # Create branch
git checkout <branch-name>          # Switch to branch
git checkout -b <branch-name>       # Create & switch to branch

βœ… Merging Branches

git merge <branch-name>             # Merge branch into current

βœ… Delete Branch

git branch -d <branch-name>         # Delete branch locally

πŸ‘©πŸ»β€πŸ’»create a new repository on the command line

echo "# 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 GitHub

πŸ”„ Push an Existing Local Repository

git remote add origin https://github.com/your-username/your-repository.git
git branch -M main
git push -u origin main

⚠️ Common Errors and Fixes

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>

πŸ’‘ Useful Tips

  • 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.

πŸš€ Example Workflow

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 main

🌟 Useful Links


πŸ“¬ Contact

Made with ❀️ by Selvaneyas


About

Github Basics for learning

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages