Post

1.3 - Git Basics - GitHub Foundations

1. What is Git?

  • Git is a version control system, which is a tool that helps you track changes in your files, especially when you’re writing code.

  • Git is like a “save” button for your code. When you’re writing code, you might want to save different versions of it as you make changes. It lets you go back to an earlier version if you make a mistake, try out new ideas without messing up the original, and work together with others on the same project.

2. What is GitHub?

  • GitHub is like a cloud storage for your code. It allows you to save your code online and share it with others. It also helps you work with other people on the same project by merging everyone’s work together.

3. Repository (Repo):

  • A repository is like a folder where your project lives. It holds all the code files, the history of changes, and all the different versions of your project.

4. Commit:

  • A commit is like taking a snapshot of your code at a certain point. It saves the current state of your project. You usually add a message to describe what changes you made.

5. Branch:

  • A branch is like a copy of your project where you can make changes without affecting the main version. Once you’re happy with your changes, you can merge them back into the main branch.

6. Merge:

  • Merging means combining the changes from one branch into another. It’s like putting together all the updates and making sure they work well together.

7. Pull Request (PR):

  • A pull request is like asking someone to review your changes before they are merged into the main project. It’s a way to make sure everything is correct before finalizing it.

8. Clone:

  • Cloning is like downloading a copy of someone’s project onto your computer so you can work on it. It’s your own version that you can make changes to.

9. Push:

  • Pushing is like uploading your changes from your computer to GitHub so others can see them.

10. Pull:

  • Pulling is like downloading the latest version of the project from GitHub to your computer. It ensures you have the most up-to-date code.

Installing Git:

  • Windows: Download and install from Git for Windows.
  • Mac: Use Homebrew: brew install git.
  • Linux: Use the package manager:
    • sudo apt-get install git (Debian/Ubuntu)
    • sudo yum install git (Fedora).

Basic Git Commands for Version Control

  • Set up Git:
    1
    2
    
    git config --global user.name "Your Name"
    git config --global user.email "your-email@gmail.com"
    
  • Initialize a new repository:
    1
    
    git init
    
  • Clone an existing repository:
    1
    
    git clone https://github.com/username/repository.git
    
  • Check the status of your repository:
    1
    
    git status
    
  • Add changes to the staging area:
    1
    2
    
    git add filename
    git add .  # To add all changed files
    
  • Commit changes:
    1
    
    git commit -m "Your commit message"
    
  • Push changes to a remote repository:
    1
    
    git push origin branch-name
    
  • Pull updates from a remote repository:
    1
    
    git pull origin branch-name
    
  • Create a new branch:
    1
    
    git branch new-branch-name
    
  • Switch to a branch:
    1
    
    git checkout branch-name
    
  • Merge a branch into your current branch:
    1
    
    git merge branch-name
    
  • View commit history:
    1
    
    git log
    

Like, Share & Subscribe Now

Follow our Creators

Join Our Exclusive Community

Follow us on Social Media

Our Website: Visit us

This post is licensed under CC BY 4.0 by the author.