Skip to content

Piyush-linux/Lets-Learn-Git

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

GIT

Git Tutorial for Beginners

1. What is Git?

  • Git is a distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
  • It tracks changes to files, allowing multiple people to work on them simultaneously, coordinating their work seamlessly.

2. Installing Git

  • Linux: Install via package manager (apt, yum, etc.).
    sudo apt-get install git  # Debian/Ubuntu
    sudo yum install git      # CentOS/Fedora
  • Mac: Install Git using Homebrew or download from the Git website.
    brew install git         # Homebrew
  • Windows: Download and install from Git for Windows.

3. Configuring Git

  • Set your username and email address:
    git config --global user.name "Your Name"
    git config --global user.email "your.email@example.com"
    git --version # To confirm that git is installed and configured correctly on your machine

4. Creating a Git Repository

  • Initialize a new Git repository:
    git init

5. Basic Git Workflow

  • Checking Status:

    git status
  • Adding Files:

    git add <filename>     # Stage specific file
    git add .              # Stage all files
  • Committing Changes:

    git commit -m "Commit message"

6. Branching and Merging

  • Creating a Branch:

    git branch <branch-name>
    git checkout <branch-name>   # Switch to the new branch
  • Merging Branches:

    git checkout main           # Switch to main branch (or target branch)
    git merge <branch-name>     # Merge changes from <branch-name> into main

7. Remote Repositories (GitHub)

  • Linking to a Remote Repository:

    git remote add origin <remote-url>   # Add a remote repository
  • Pushing Changes:

    git push -u origin main     # Push local changes to the remote repository
  • Pulling Changes:

    git pull origin main        # Pull latest changes from remote repository

8. Resolving Conflicts

  • Conflict Resolution:
    • Edit conflicted files to resolve conflicts.
    • Add resolved files using git add and commit changes.

9. Git History and Log

  • Viewing Commit History:
    git log                # View commit history
    git log --oneline      # Compact view of commit history

10. Additional Git Commands

  • Undoing Changes:

    git reset HEAD <filename>   # Unstage changes
    git checkout -- <filename>  # Discard changes in working directory
  • Git Help:

    git --help             # Git command help

11. Git Resources

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors