Skip to content

anushrithvic/learnGit

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Git and GitHub: A Complete Guide

This repository was created to learn Git and GitHub more practically by implementing all commands.
I have included all of the concepts I have learned in this readme file, do use it.


Table of Contents

  1. What is Git?
  2. What is GitHub?
  3. Installing Git
  4. Configuring Git
  5. Basic Git Workflow
  6. Important Git Commands
  7. Branching and Merging
  8. Remote Repositories
  9. Stashing and Cleaning
  10. Git Logs and History
  11. GitHub Workflow
  12. Collaborating on GitHub
  13. Advanced Git Commands
  14. Troubleshooting Git Issues
  15. Resources

What is Git?

Git is a distributed version control system designed to track changes in source code efficiently. It enables multiple developers to collaborate on projects by maintaining version histories and managing branches.

What is GitHub?

GitHub is a web-based platform for version control and collaboration using Git. It provides hosting for Git repositories and adds features like pull requests, issue tracking, and project management tools.


Installing Git

  1. Windows: Download from git-scm.com and follow the installer.
  2. Mac: Use Homebrew: brew install git.
  3. Linux: Use the package manager:
    sudo apt-get install git # Debian/Ubuntu
    sudo yum install git     # RHEL/CentOS

Verify installation:

git --version

Configuring Git

Set up your identity:

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

Check configuration:

git config --list

Basic Git Workflow

  1. Initialize a repository:
    git init
  2. Add files to staging area:
    git add <file>
    git add . # Add all changes
  3. Commit changes:
    git commit -m "Commit message"
  4. Push to remote repository:
    git push origin main

Important Git Commands

Create a new repository

git init

Clone a repository

git clone <repository-url>

Check repository status

git status

Stage changes

git add <file>
git add .

Commit changes

git commit -m "Your message here"

View commit history

git log

View specific file changes

git diff

Branching and Merging

Create a branch

git branch <branch-name>

Switch to a branch

git checkout <branch-name>

Create and switch to a branch

git checkout -b <branch-name>

Merge a branch

git merge <branch-name>

Delete a branch

git branch -d <branch-name>

Remote Repositories

Add a remote repository

git remote add origin <repository-url>

View remotes

git remote -v

Push changes to a remote repository

git push origin <branch-name>

Pull changes from a remote repository

git pull origin <branch-name>

Stashing and Cleaning

Stash changes

git stash

Apply stashed changes

git stash apply

Drop a stash

git stash drop

Clean untracked files

git clean -f

Git Logs and History

Show commit history

git log

Show one-line summary of commits

git log --oneline

Show graphical representation

git log --graph --oneline --all

GitHub Workflow

  1. Create a repository on GitHub.
  2. Clone it locally:
    git clone <repository-url>
  3. Make changes, stage, and commit:
    git add .
    git commit -m "Description of changes"
  4. Push changes:
    git push origin main

Collaborating on GitHub

Fork a repository

  1. Click "Fork" on GitHub.
  2. Clone your fork:
    git clone <fork-url>

Open a pull request

  1. Commit changes to your fork.
  2. Push changes and click "Pull Request" on GitHub.

Advanced Git Commands

Revert a commit

git revert <commit-hash>

Reset to a previous commit

git reset --hard <commit-hash>

Rebase

git rebase <branch>

Cherry-pick a commit

git cherry-pick <commit-hash>

Troubleshooting Git Issues

Undo the last commit

git reset --soft HEAD~1

Resolve merge conflicts

  1. Edit conflicted files.
  2. Add changes:
    git add <file>
  3. Commit:
    git commit

Check unmerged files

git status

Resources

Git and GitHub for Beginners - Crash Course | freeCodeCamp
Git and GitHub learning resources | GitHub

This README aims to serve as a quick reference for all key Git and GitHub concepts. Happy coding!

About

my learning process

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%