Skip to content

ChaitanyaShah26/git-github-tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

git      github

Git & GitHub Tutorial 🚀


Welcome to the ultimate guide to mastering Git and GitHub! 👋 This repository is designed to be a beginners guide to learn and get a handy reference for Git & GitHub.

🛠️ Getting Started: Setup

Before you can use Git, you need to set it up on your computer.

1. Create a GitHub Account 🌐

  • Go to github.com and sign up for a free account.

2. Install Git on Your Machine 💻

  • Windows: Download and install Git for Windows.
  • Mac: Open your terminal and run git --version. If you don't have it, it will prompt you to install Xcode Command Line Tools.
  • Linux: Open your terminal and use your distribution's package manager, e.g., sudo apt-get install git.

3. Configure Git ⚙️

After installing Git, introduce yourself! This information will be attached to every commit you make.

git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"

🌟 Learn by Doing!

The best way to learn is by getting hands-on with the concept. In the steps below, you will practice the complete, basic workflow of contributing to an open-source project on GitHub.

What you'll be doing: You'll create your own copy of this project, download it to your computer, make a small change, and then propose that your change be added to the main project.

Note

Don't worry if you don't understand what forking, cloning or pull requests mean yet. Just follow the steps, and you'll understand it all by the end of this tutorial!

Get Started by following these steps:

  1. Star this repository: Click the 'Star' button on the top right. ⭐
  2. Fork this repository: Click the 'Fork' button. This creates your own copy of this project. 🍴
  3. Clone your fork: On your forked repository's page, click the green "Code" button and copy the URL. Then, run this command in your terminal:
    git clone [the-url-you-copied]
  4. Make a contribution: Navigate into the new folder (cd YOUR-REPONAME) and add your name to the CONTRIBUTING.md file using a text editor.
  5. Commit and Push your change: Save the file, and then run these commands in your terminal:
    git add CONTRIBUTING.md
    git commit -m "Add [Your Name] to contributors"
    git push origin main
  6. Open a Pull Request: Go back to your forked repository on GitHub. You should see a yellow banner that says "This branch is 1 commit ahead of the original repository." Click the "Contribute" button, then "Open pull request." Follow the steps to submit your change.

Congratulations! You've just completed the core workflow of a GitHub contributor. 🎉

🧠 Core Git Concepts

1. What is Git & GitHub? 🤔

  • Git is a distributed version control system. Think of it as a program on your computer that takes "snapshots" (called commits) of your code. It allows you to track changes, go back to previous versions, and work on different features in parallel.
  • GitHub is a cloud-based platform that hosts your Git repositories. It adds a powerful web interface and tools for collaboration, like pull requests and issues, on top of Git.

Important

Run all the commands on your cmd or git bash

2. Repositories (Repos) 📂

A repository is a folder for your project that contains all its files and the entire history of changes.

🚀 Try it yourself! Create a new project on your local machine.

mkdir my-first-repo
cd my-first-repo
git init

The git init command creates a hidden .git subfolder, which turns the directory into a Git repository.

3. The Commit Cycle: Add & Commit 🔄

A commit is a snapshot of your changes. It's a saved state of your code. This is a two-step process:

  1. Staging (git add): Choosing which changes you want to include in the next snapshot.
  2. Committing (git commit): Taking the snapshot with a descriptive message.

🚀 Try it yourself! Let's make your first local commit.

# In your 'my-first-repo' directory
echo "Hello, Git!" > greeting.txt
git status  # See that greeting.txt is "untracked"
git add greeting.txt
git status  # Now see it's "staged for commit"
git commit -m "Add greeting file"
git log     # See your commit history!

4. Branches in Git 🌳

A branch is an independent line of development. You create branches to work on new features or bug fixes without disturbing the main codebase (often the main branch).

🚀 Try it yourself! Create a branch to test a new idea.

# Create a new branch and switch to it
git checkout -b new-idea

# Make a change on this new branch
echo "This is a new idea." >> greeting.txt

# Commit the change on the 'new-idea' branch
git add greeting.txt
git commit -m "Experiment with a new idea"

# Switch back to your main branch
git checkout main

# Notice that greeting.txt no longer contains "This is a new idea."
cat greeting.txt

5. Merging ✅

Merging (git merge) combines the changes from one branch into another. This is how you integrate a new feature into your main codebase after you're done working on it.

🚀 Try it yourself! Merge the new-idea branch you created.

# Make sure you are on the main branch
git checkout main

# Merge the changes from 'new-idea' into 'main'
git merge new-idea

# Check the file - the changes are now here!
cat greeting.txt

6. Merge Conflicts 🤯

This happens when Git can't automatically merge two branches, usually because they have conflicting changes on the same line of a file. You have to manually edit the file to resolve the conflict before the merge can be completed.

7. Stashing 🗄️

git stash temporarily shelves changes you've made so you can switch branches to work on something else without committing incomplete work.

🚀 Try it yourself!

# On your main branch, make an edit but don't commit
echo "An unfinished thought..." >> thoughts.txt
git status # Shows an uncommitted change

# Stash the change to work on something else
git stash
git status # Your working directory is now clean!

# Bring your changes back
git stash pop
git status # Your change is back

8. Issues 🎟️

GitHub Issues are a built-in bug and task tracker for your repository. They're perfect for keeping track of ideas, bugs, and tasks. You can create them on the "Issues" tab on your GitHub repository page.

🍴 A Deeper Dive: Forks and Pull Requests

This is the heart of collaboration on GitHub.

  1. Forking a Repository: A fork is your personal copy of another user's repository that lives on your account. You fork a project so you can work on it without affecting the original.
  2. Cloning Your Fork: After forking, you git clone your fork to your local machine to start working.
  3. Pushing to Your Fork: As you make commits, you git push them to your forked repository on GitHub, not to the original project.
  4. Opening a Pull Request (PR): When you are ready to share your work, you open a Pull Request. A PR is a request to the original repository's maintainers to "pull" your changes into their project. This is where code reviews and discussions happen before your code is merged.

📚 What's Next? & Some Resources

You've now learned the core concepts of Git and GitHub! Keep practicing, and you'll be a pro in no time.

youtube YouTube Video Resources: Apna College Git/GitHub Tutorial
freeCodeCamp Git/GitHub Tutorial

🌟🌟

If you found this guide helpful, consider giving it a star ⭐ and helps other discover it!

@ChaitanyaShah26

About

A complete guide to get acquainted with working of Git & GitHub.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published