Skip to content

Latest commit

 

History

History
140 lines (109 loc) · 2.11 KB

File metadata and controls

140 lines (109 loc) · 2.11 KB

Basic Git Commands

This README provides a quick reference for essential Git commands used in day-to-day development.


1. Initialize a Repository

git init

Initializes a new Git repository in the current directory.


2. Clone a Repository

git clone <repository-url>

Creates a local copy of a remote repository.


3. Check Repository Status

git status

Shows the status of your working directory and staging area.


4. Add Files to Staging Area

git add <file-name>
# or
git add .

Stages changes for commit.


5. Commit Changes

git commit -m "Your commit message"

Saves staged changes with a message.


6. View Commit History

git log

Displays the commit history of the repository.


7. Create and Switch Branches

git branch <branch-name>
git checkout <branch-name>
# or
git switch <branch-name>

Creates and moves to a new branch.


8. Pull Latest Changes

git pull

Fetches and merges changes from the remote repository.


9. Push Changes

git push origin <branch-name>

Uploads your commits to the remote repository.


10. Merge Branches

git checkout <target-branch>
git merge <source-branch>

Merges changes from one branch into another.


11. Discard Local Changes

git checkout -- <file-name>
# or
git reset --hard

Reverts changes in your working directory.


12. Remove Files

git rm <file-name>

Removes a file from the working directory and stages the deletion.


13. Set Remote Repository

git remote add origin <repository-url>

Links your local repo to a remote GitHub repository.


Uploading This README to GitHub

  1. Create a GitHub repo.
  2. Initialize Git (if not already):
    git init
  3. Add and commit the README:
    git add README.md
    git commit -m "Add basic Git commands README"
  4. Add remote:
    git remote add origin <your-repo-url>
  5. Push to GitHub:
    git push -u origin main

Your README is now uploaded to GitHub!