Skip to content

Rohit-2301/Git-Github_Basics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 

Repository files navigation

πŸš€ Git & GitHub Basics

Git is a version control system that helps developers manage and track changes in their code, while GitHub is a cloud-based platform for hosting Git repositories and collaborating with others. This guide covers the essential Git commands and workflows to get you started.


πŸ“Œ What is Git?

Git is a distributed version control system that allows multiple developers to work on a project efficiently, keeping track of changes and enabling easy collaboration.

πŸ”§ Basic Git Commands and Their Usage

Command Description
git init Initializes a new Git repository in your local project directory.
git clone <repo_url> Downloads (clones) a repository from GitHub to your local machine.
git status Shows the current state of your repository (modified, staged, or untracked files).
git add <file> Adds a specific file to the staging area before committing.
git add . Stages all modified and new files in the repository.
git commit -m "message" Saves (commits) the staged changes with a meaningful message.
git push origin <branch> Uploads (pushes) local commits to a remote GitHub repository on the specified branch.
git pull origin <branch> Fetches and merges the latest changes from a remote repository into your local branch.
git log Displays a history of commits made in the repository.
git branch Lists all branches in the repository and highlights the current branch.
git checkout -b <new-branch> Creates and switches to a new branch for feature development.
git merge <branch> Merges changes from another branch into the current branch.
git reset --hard HEAD~1 Removes the last commit permanently from history.
git revert <commit_id> Creates a new commit that undoes a previous commit without modifying history.
git checkout -- <file> Discards changes made to a specific file before committing.
git remote -v Displays the URLs of remote repositories linked to your project.
git stash Temporarily saves changes that are not yet committed, allowing you to switch branches.
git stash pop Restores the most recently stashed changes.
git rm <file> Removes a file from the repository and deletes it from the working directory.

πŸ“Œ What is GitHub?

GitHub is a web-based platform that hosts Git repositories, making it easy for developers to collaborate on projects, track issues, and review code.

πŸ”— Basic GitHub Workflow

  1. Create a Repository

    • Go to GitHub β†’ Click New Repository β†’ Enter a name β†’ Click Create Repository
  2. Clone the Repository (Download it Locally)

    git clone <repo_url>
    cd <repo_name>

πŸ“Œ Create a GitHub Repository Using Terminal

Follow these steps to create and push a new GitHub repo using terminal:

βœ… Step 1: Create a New Directory and Initialize Git

mkdir <project_name>
cd <project_name>
git init

βœ… Step 2: Create Files and Make Initial Commit

echo "# Project Title" > README.md
git add .
git commit -m "Initial commit"

βœ… Step 3: Create a Repository on GitHub

  • Go to GitHub β†’ New Repository β†’ Enter name β†’ Click Create Repository
  • DO NOT initialize with README, .gitignore, or license.

βœ… Step 4: Link Local Repo to GitHub Remote and Push

git remote add origin https://github.com/<your_username>/<repo_name>.git
git branch -M main
git push -u origin main

πŸ“Œ Steps to Add a File to GitHub Using Git & VS Code

Follow these steps to add and upload a new file to your GitHub repository:

βœ… Step 1: Open Your Project in VS Code

  • Open VS Code and navigate to your project folder.

βœ… Step 2: Create or Add a File

  • Add a new file or modify an existing file in the project directory.

βœ… Step 3: Open Terminal in VS Code

  • Open the terminal (Ctrl + ~ on Windows/Linux or Cmd + ~ on Mac).

βœ… Step 4: Check the Status of Your Repository

git status
  • This shows any new, modified, or deleted files.

βœ… Step 5: Add the File to Staging Area

git add <filename>  # Adds a specific file
git add .  # Adds all new and modified files

βœ… Step 6: Commit the Changes

git commit -m "Added <filename>"
  • Write a meaningful commit message describing the change.

βœ… Step 7: Push the Changes to GitHub

git push origin main
  • If you're working on a different branch, replace main with your branch name.

βœ… Step 8: Verify on GitHub

  • Go to your GitHub repository and check if the file is uploaded.

πŸš€ Now your file is successfully added to GitHub! πŸŽ‰


πŸ“Œ Steps to Remove a File from GitHub Using Git & VS Code

Follow these steps to remove a file from your GitHub repository:

βœ… Step 1: Open Your Project in VS Code

  • Open VS Code and navigate to your project folder.

βœ… Step 2: Open Terminal in VS Code

  • Open the terminal (Ctrl + ~ on Windows/Linux or Cmd + ~ on Mac).

βœ… Step 3: Remove the File

git rm <filename>
  • This removes the file from your local repository.

βœ… Step 4: Check the Status of Your Repository

git status
  • Verify that the file is marked as deleted.

βœ… Step 5: Commit the Changes

git commit -m "Removed <filename>"
  • Write a meaningful commit message describing the removal.

βœ… Step 6: Push the Changes to GitHub

git push origin main
  • If you're working on a different branch, replace main with your branch name.

βœ… Step 7: Verify on GitHub

  • Go to your GitHub repository and check if the file is removed.

πŸš€ Now your file is successfully removed from GitHub! πŸš—οΈ

About

This repository consists of basics of Git and Github

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published