1. The Core Concept: The Git Workflow
To understand Git, you must understand the three stages a file goes through before it is saved permanently:
Working Directory: Where you are currently making changes to your files.
Staging Area (Index): A "prep zone" where you pick which changes are ready to be saved.
Local Repository: Where Git permanently stores the versions (commits) of your project.
Remote Repository (GitHub): The online version of your project where your local code is uploaded.
2. Essential Git Commands
Once you have Git installed, you will use these commands in your terminal or command prompt:
Setup & Starting
git init: Creates a new Git repository in your current folder.git clone [URL]: Downloads an existing project from GitHub to your computer.
The Daily Cycle
git status: Shows which files have been modified and what is in the staging area.git add [filename]: Moves a file to the Staging Area. Usegit add .to add everything.git commit -m "message": Saves your changes to the Local Repository with a descriptive note.git push: Sends your local commits to GitHub.git pull: Downloads the latest changes from GitHub to your computer.
3. Branching: The "Parallel Universe."
Branching is Git's most powerful feature. It allows you to work on a new feature without breaking the "Main" (working) version of your code.
git branch [name]: Creates a new branch.git checkout [name]: Switches you to that branch.git merge [name]: Combines the changes from your feature branch back into the main branch.
4. How to Use GitHub
While Git is the engine, GitHub is the platform. Here is how to get a project live:
Create a Repo: On GitHub, click "New Repository."
Link Local to Remote: Run the command GitHub provides (usually
git remote add origin [URL]).Push Code: Use
git push -u origin mainto send your code to the site.Pull Requests (PRs): If you are working on a team, you submit a Pull Request to ask the owner to "pull" your changes into their project.
5. Summary Table: Git vs. GitHub
| Feature | Git | GitHub |
| What is it? | Software (Tool) | Service (Website) |
| Installation | Installed locally on your PC. | Accessed via a web browser. |
| Purpose | Tracks version history. | Hosts and shares Git repositories. |
| Internet | Works offline. | Requires internet to upload/download. |
| Interface | Command Line (usually). | Graphical User Interface (GUI). |
Common "Save Me" Command
If you ever get stuck or want to see your history, use:git log --oneline --graph --all
This provides a visual map of your commits and branches directly in your terminal.
Would you like me to guide you through your first "Commit and Push" to GitHub, or would you prefer to learn about resolving Merge Conflicts?
0 Comments