Skip to content

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

name

Git Notes: Comprehensive Overview with Explanations

Part 1: Git Basics

Task 1: Install and Configure Git

What to do: Install Git and configure it to associate commits with your name and email.

Steps:

  1. Install Git from git-scm.com.
  2. Configure your username and email:
    git config --global user.name "Your Name"
    git config --global user.email "your-email@example. com"
  • Verify configuration:
     git config --list

Task 2: Initialize a Repository

  • Create and initialize a directory as a Git repository:
      mkdir MyProject
      cd MyProject
      git init
  • Purpose: Creates a .git folder to track changes.

Part 2: Basic Workflow

Task 3: Creating and Committing Files

  • Create a file:
echo "Hello Git" > file1.txt
  • Stage and commit:
git add file1.txt
git commit -m "Initial commit: Added file1.txt"

Task 4: Viewing Changes

  • Modify the file:
echo "Git is awesome!" >> file1.txt
  • Check status and differences:
git status
git diff

Task 5: Undoing Changes

  • Unstage a staged file:
git reset file1.txt
  • Discard uncommitted changes:
git checkout -- file1.txt

Part 3: Branching and Merging

Task 6: Branch Management

  • Create a new branch:
git checkout -b feature-branch
  • List branches:
git branch
  • Rename a branch:
git branch -m feature-branch feature-enhanced

Task 7: Merging Branches

  • Merge a branch into the main branch:
git checkout main
git merge feature-enhanced

Task 8: Handling Merge Conflicts

  • Resolve conflicts during merge:
git merge <branch-name>
git add <resolved-file>
git commit

Part 4: Remote Repositories

Task 9: Remote Setup

  • Add a remote repository:
git remote add origin https://github.com/your-username/repo.git
  • Verify the remote:
git remote -v

Task 10: Push and Pull

  • Push changes:
git push -u origin main
  • Pull changes:
git pull origin main

Task 11: Cloning a Repository

  • Clone a remote repository:
git clone https://github.com/your-username/repo.git

Part 5: Advanced Git

Task 12: Stashing Changes

  • Save uncommitted changes:
git stash
  • Apply stashed changes:
git stash apply
  • Drop the stash:
git stash drop

Task 13: Tagging Commits

  • Tag the current commit:
git tag -a v1.0 -m "Version 1.0 release"
  • Push the tag:
git push origin v1.0

Task 14: Rewriting Commit History

  • Use interactive rebase:
git rebase -i HEAD~3
  • Replace pick with edit or squash as needed.

Task 15: Cherry-Picking Commits

  • Apply a specific commit to another branch:
git cherry-pick <commit-hash>

Part 6: Collaboration

Task 16: Forking and Pull Requests

  • Fork a repository and clone it locally:
git clone https://github.com/your-username/forked-repo.git
  • Create a branch, make changes, and push:
git checkout -b fix-typo
echo "Typo fixed" >> README.md
git add README.md
git commit -m "Fixed a typo"
git push origin fix-typo
  • Open a pull request on GitHub.

Task 17: Simulating Team Collaboration

  • Simulate conflicts by modifying the same file in two branches.
  • Practice resolving conflicts with teammates.

Part 7: Ignoring Files

Task 18: Using .gitignore

  • Create a .gitignore file:
echo "node_modules/" > .gitignore
  • Add and commit the .gitignore:
git add .gitignore
git commit -m "Added .gitignore"
  • Verify ignored files:
git status

Part 8: Automation and Cleanup

Task 19: Cleaning the Repository

  • Remove untracked files:
git clean -f

Task 20: Aliases and Shortcuts

  • Create aliases:
git config --global alias.st status
git config --global alias.cm commit
  • Use the aliases:
git st
git cm -m "Message"

======= name

feature-enhanced

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors