Git Commands
Git Commands - Working Locally and Remotely:
- Git Commands 
- Initialize repository: - $git init
- Stage files: - $git add filename
- Commit changes: - $git commit -m "commit message"
- Check status: - $git status
- Clone repo: - $git clone [repo_url]
- Push changes: - $git push origin main
Activity: Follow these detailed steps to create a local repository, add and commit a file, and push it to GitHub:
- Initialize a Local Repository: - Open Terminal (Mac/Linux) or Command Prompt (Windows). 
- Create a new directory: - $mkdir- GitExample- && cd- GitExample
- Initialize Git in this directory: - $git init
 
- Create and Add a File: - Create a text file: - $echo "This is my first Git file" >- example.txt
- Stage the file for commit: - $git add- example.txt
- Verify the staged file: - $git status
 
- Commit the File Locally: - Commit the file with a message: - $git commit -m "Initial commit with example.txt"
- Confirm the commit: - $git log
 
- Push to GitHub: - Go to GitHub and create a new repository (e.g., - GitExampleRepo). Do NOT initialize it with a README.
- Copy the repository URL from GitHub (choose HTTPS). 
- Link your local repository to GitHub: - $git remote add origin https://github.com/YourUsername/GitExampleRepo.git
 
- Push your commit to GitHub: - $git push -u origin main
 
 
- Verify on GitHub: - Go to your GitHub repository and refresh the page to see your - example.txtfile.
 
By completing this activity, you will understand how to initialize a local Git repository, commit changes, and push them to a remote repository on GitHub
Last updated