{"id":25949698,"url":"https://github.com/programmersiam/learning-git-github-2025","last_synced_at":"2026-04-29T09:01:39.189Z","repository":{"id":280216565,"uuid":"941304139","full_name":"ProgrammerSiam/Learning-Git-GitHub-2025","owner":"ProgrammerSiam","description":"A complete reference guide to Git and GitHub with all essential commands, concepts, and practical workflows.","archived":false,"fork":false,"pushed_at":"2025-03-02T02:46:25.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-03T02:11:37.290Z","etag":null,"topics":["git","github","version-control"],"latest_commit_sha":null,"homepage":"https://programmersiam.github.io/Learning-Git-GitHub-2025/","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ProgrammerSiam.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-02T00:56:51.000Z","updated_at":"2025-03-02T02:46:29.000Z","dependencies_parsed_at":"2025-03-02T03:27:07.273Z","dependency_job_id":"27afa1a2-bff8-464f-bfc4-cc7ae4281c63","html_url":"https://github.com/ProgrammerSiam/Learning-Git-GitHub-2025","commit_stats":null,"previous_names":["programmersiam/learning-git-github-2025"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ProgrammerSiam/Learning-Git-GitHub-2025","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProgrammerSiam%2FLearning-Git-GitHub-2025","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProgrammerSiam%2FLearning-Git-GitHub-2025/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProgrammerSiam%2FLearning-Git-GitHub-2025/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProgrammerSiam%2FLearning-Git-GitHub-2025/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ProgrammerSiam","download_url":"https://codeload.github.com/ProgrammerSiam/Learning-Git-GitHub-2025/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProgrammerSiam%2FLearning-Git-GitHub-2025/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262381858,"owners_count":23302255,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git","github","version-control"],"created_at":"2025-03-04T12:28:45.839Z","updated_at":"2026-04-29T09:01:34.148Z","avatar_url":"https://github.com/ProgrammerSiam.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Comprehensive Git \u0026 GitHub Guide 📘\n\nA complete reference guide to Git and GitHub with all essential commands, concepts, and practical workflows.\n\n## Table of Contents\n\n- [What Is Git \u0026 GitHub?](#what-is-git--github)\n- [Why Use Git \u0026 GitHub?](#why-use-git--github)\n- [What Can Git \u0026 GitHub Do?](#what-can-git--github-do)\n- [Who Discovered Git \u0026 GitHub?](#who-discovered-git--github)\n- [How Do Git \u0026 GitHub Work?](#how-do-git--github-work)\n- [Understanding Repository Types](#understanding-repository-types)\n- [Core Git Concepts](#core-git-concepts)\n  - [HEAD](#head)\n  - [Branches](#branches)\n  - [Main/Master Branch](#mainmaster-branch)\n  - [Remote and Local](#remote-and-local)\n  - [Tracking Branches](#tracking-branches)\n- [Essential Git Commands](#essential-git-commands)\n  - [Git Setup](#git-setup)\n  - [Git Basics](#git-basics)\n  - [Getting \u0026 Creating Projects](#getting--creating-projects)\n  - [Basic Snapshotting](#basic-snapshotting)\n  - [Branching \u0026 Merging](#branching--merging)\n  - [Sharing \u0026 Updating Projects](#sharing--updating-projects)\n  - [Inspection \u0026 Comparison](#inspection--comparison)\n  - [Git Reset \u0026 Remove Commands](#git-reset--remove-commands)\n  - [Git Push, Fetch, Pull](#git-push-fetch-pull)\n  - [Git Stash Commands](#git-stash-commands)\n  - [Advanced Git Commands](#advanced-git-commands)\n- [Git Workflows](#git-workflows)\n- [Common Git Problems and Solutions](#common-git-problems-and-solutions)\n- [Frequently Asked Questions (FAQ)](#frequently-asked-questions-faq)\n- [Additional Resources](#additional-resources)\n\n## What Is Git \u0026 GitHub? 💻🌐\n\n### Git:\n\nGit is a distributed version control system. It allows every developer to have a complete copy of the project repository on their local machine. This setup makes it easy to work offline, experiment with new features in branches, and merge changes with the main project.\n\n### GitHub:\n\nGitHub is a cloud-based platform that hosts Git repositories. It not only stores your code but also offers collaboration tools such as issue tracking, pull requests, and code reviews. GitHub makes it easier for teams to work together and share their work publicly or privately.\n\n## Why Use Git \u0026 GitHub? 🤝✅\n\n### Collaboration:\n\nMultiple developers can work on the same project simultaneously without overwriting each other's changes.\n\n### History Tracking:\n\nEvery change is recorded, allowing you to review, revert, or audit modifications over time.\n\n### Branching \u0026 Merging:\n\nYou can create separate branches to develop new features or fix bugs independently and then merge them back into the main codebase.\n\n### Backup \u0026 Recovery:\n\nWith distributed copies, your work is backed up, and you can recover previous versions if something goes wrong.\n\n### Community \u0026 Integration:\n\nGitHub has a vast ecosystem with tools for continuous integration, deployment, and more, making it an excellent platform for both open-source and private projects.\n\n## What Can Git \u0026 GitHub Do? 🚀🔧\n\n### Version Control:\n\nTrack changes in your code, view commit histories, and revert to previous states if necessary.\n\n### Collaboration Tools:\n\nFacilitate team collaboration with pull requests, code reviews, and issue tracking.\n\n### Branching:\n\nExperiment safely by creating branches for new features or fixes without disturbing the main project.\n\n### Integration \u0026 Automation:\n\nWork with CI/CD pipelines, automated testing, and deployment tools that integrate directly with GitHub.\n\n### Documentation \u0026 Community:\n\nHost project documentation, wikis, and even community forums directly on GitHub to support user engagement and developer communication.\n\n## Who Discovered Git \u0026 GitHub? 👨‍💻👩‍💻\n\n### Git:\n\nGit was created by Linus Torvalds in 2005. He developed it to support the Linux kernel development, aiming for a fast, efficient, and reliable version control system.\n\n### GitHub:\n\nGitHub was founded in 2008 by Tom Preston-Werner, Chris Wanstrath, PJ Hyett, and Scott Chacon. It quickly became popular due to its user-friendly interface and robust collaboration features, transforming how developers manage and share code.\n\n## How Do Git \u0026 GitHub Work? 🔄📥\n\n### Local Repositories:\n\nWith Git, every developer works on a local copy of the entire repository, which includes the full history of changes. This setup allows developers to commit changes locally.\n\n### Commits \u0026 Branches:\n\nChanges are saved as commits. Developers can create branches to develop features independently. Once tested, these branches can be merged back into the main branch.\n\n### Remote Repositories:\n\nGitHub acts as a central hub where developers can push their local changes and pull updates made by others. This exchange keeps everyone in sync.\n\n### Pull Requests \u0026 Code Reviews:\n\nOn GitHub, a developer can open a pull request to propose changes. Team members review the code, discuss improvements, and finally merge the changes once they're approved.\n\n### Issue Tracking \u0026 Project Management:\n\nGitHub provides tools to manage bugs, feature requests, and project workflows, ensuring organized and efficient project development.\n\n## Understanding Repository Types\n\n### Local Repository:\n\nA local repository resides on your personal computer or workstation. This is where you perform all your work - writing code, making changes, committing updates, and tracking history.\n\n- Contains the complete history of your project including all commits, branches, and files\n- Lives in the `.git` directory of your project\n- Allows you to work offline without internet connection\n- Contains your working directory, staging area, and local commit history\n\n### Remote Repository:\n\nA remote repository is hosted on a server (like GitHub, GitLab, or Bitbucket) and serves as a centralized location where team members can share and synchronize their work.\n\n- Facilitates collaboration between multiple developers\n- Provides backup and redundancy for your code\n- Serves as the official source of the project\n- Enables features like pull requests, code reviews, and issue tracking\n- Popular remote repository hosts include GitHub, GitLab, and Bitbucket\n\n### Relationship Between Local and Remote:\n\n- Local repositories can be linked to one or more remote repositories\n- You push local changes to remote repositories to share them\n- You pull changes from remote repositories to update your local copy\n- Remote repositories are usually referred to by names like \"origin\" or \"upstream\"\n\n## Core Git Concepts\n\n### HEAD\n\nHEAD is a special pointer that references the current location in your repository:\n\n- Points to the tip of the current branch you are working on\n- Represents the last commit in your current branch\n- Acts as a \"You are here\" marker in your commit history\n- When you switch branches, HEAD moves to point to the tip of the new branch\n- Can be in a \"detached\" state when you checkout a specific commit instead of a branch\n\nExample of accessing HEAD:\n\n```bash\n# See what HEAD points to\ncat .git/HEAD\n\n# Move HEAD to a specific commit (detached HEAD state)\ngit checkout \u003ccommit-hash\u003e\n\n# Return HEAD to a branch\ngit checkout \u003cbranch-name\u003e\n```\n\n### Branches\n\nA branch is an independent line of development within a repository:\n\n- Branches allow multiple developers to work in parallel without interfering with each other\n- Each branch is essentially a pointer to a specific commit\n- New commits on a branch advance that branch's pointer\n- The default branch (typically main or master) represents the primary line of development\n- Feature branches, bugfix branches, and release branches are common types of branches\n\nBranch operations:\n\n```bash\n# Create a new branch\ngit branch \u003cbranch-name\u003e\n\n# Switch to a branch\ngit checkout \u003cbranch-name\u003e\n\n# Create and switch to a new branch in one command\ngit checkout -b \u003cbranch-name\u003e\n\n# List all branches\ngit branch -a\n\n# Delete a branch\ngit branch -d \u003cbranch-name\u003e\n```\n\n### Main/Master Branch\n\nThe main branch (traditionally called \"master\") is the primary branch in a repository:\n\n- Represents the official, production-ready version of the project\n- Should always contain stable, working code\n- Often protected from direct pushes in collaborative projects\n- Changes to main/master typically come through pull requests and code reviews\n- May be deployed to production environments automatically\n\nNote: Many repositories now use \"main\" instead of \"master\" as the default branch name.\n\n### Remote and Local\n\nUnderstanding the relationship between remote and local references:\n\n- Remote branches have the format `\u003cremote-name\u003e/\u003cbranch-name\u003e` (e.g., `origin/main`)\n- Remote-tracking branches are local references that represent the state of branches in remote repositories\n- Local branches can track remote branches to simplify pushing and pulling changes\n\nCommon remote operations:\n\n```bash\n# Add a remote repository\ngit remote add \u003cname\u003e \u003curl\u003e\n\n# List remote repositories\ngit remote -v\n\n# Fetch updates from a remote without merging\ngit fetch \u003cremote-name\u003e\n\n# View remote branches\ngit branch -r\n```\n\n### Tracking Branches\n\nA tracking branch is a local branch that has a direct relationship to a remote branch:\n\n- Automatically knows which remote branch to push to and pull from\n- Shows how far ahead or behind the remote branch your local branch is\n- Created automatically when you clone a repository or checkout a remote branch\n- Enables `git pull` and `git push` without specifying a remote or branch\n\nSetting up tracking:\n\n```bash\n# Create a new branch that tracks a remote branch\ngit checkout --track origin/\u003cbranch-name\u003e\n\n# Make an existing branch track a remote branch\ngit branch -u origin/\u003cbranch-name\u003e\n\n# Push a local branch and set up tracking\ngit push -u origin \u003cbranch-name\u003e\n```\n\n## Essential Git Commands\n\n### Git Setup 🛠️\n\n```bash\n# 1. Set Up Your Username and Email\ngit config --global user.name \"Your Name\"\ngit config --global user.email \"your.email@example.com\"\n\n# 2. Set default editor\ngit config --global core.editor \"code --wait\"  # For VS Code\n\n# 3. Set default branch name for new repositories\ngit config --global init.defaultBranch main\n\n# 4. Configure line ending behavior\ngit config --global core.autocrlf input  # For Mac/Linux\ngit config --global core.autocrlf true   # For Windows\n\n# 5. View all configuration settings\ngit config --list\n```\n\n### Git Basics 📝\n\n```bash\n# Create a file\ntouch filename.extension\n\n# Create a folder\nmkdir foldername\n\n# Enter a folder\ncd foldername\n\n# Check the directory currently you are working in\npwd\n\n# See the list of your files\nls\n\n# See hidden files (including .git directory)\nls -a\n```\n\n### Getting \u0026 Creating Projects 🏁\n\n```bash\n# Initialize a local Git repository\ngit init\n\n# Create a local copy of a remote repository\ngit clone ssh://git@github.com/[username]/[repository-name].git\n\n# Clone a specific branch\ngit clone -b \u003cbranch-name\u003e \u003crepository-url\u003e\n\n# Clone a repository with limited history for faster cloning\ngit clone --depth=1 \u003crepository-url\u003e\n```\n\n### Basic Snapshotting 📸\n\n```bash\n# Check status\ngit status\n\n# Add a file to the staging area\ngit add [file-name.txt]\n\n# Add all new and changed files to the staging area\ngit add -A\ngit add --all\ngit add .\n\n# Stage changes in your folder you are currently staying\ngit add .\n\n# Stage changes all the files except the deleted ones\ngit add *\n\n# Stage changes of all the files of the specific extension\ngit add *.extension\n\n# Commit changes\ngit commit -m \"[commit message]\"\n\n# Commit changes and skip the staging area (add + commit)\ngit commit -am \"[commit message]\"\n\n# Amend the most recent commit message\ngit commit --amend -m \"[new commit message]\"\n\n# Remove a file (or folder)\ngit rm -r [file-name.txt]\n\n# View the remote repository of the currently working file or directory\ngit remote -v\n\n# Display the commit history, showing author, date, and commit message\ngit log\n\n# Configure Git settings, such as user name and email\ngit config\n```\n\n### Branching \u0026 Merging 🌿\n\n```bash\n# List branches (the asterisk denotes the current branch)\ngit branch\n\n# List all branches (local and remote)\ngit branch -a\n\n# Create a new branch\ngit branch [branch name]\n\n# Delete a branch\ngit branch -d [branch name]\n\n# Force delete a branch (even if not fully merged)\ngit branch -D [branch name]\n\n# Delete a remote branch\ngit push origin --delete [branch name]\n\n# Create a new branch and switch to it\ngit checkout -b [branch name]\n\n# Clone a remote branch and switch to it\ngit checkout -b [branch name] origin/[branch name]\n\n# Rename a local branch\ngit branch -m [old branch name] [new branch name]\n\n# Switch to a branch\ngit checkout [branch name]\n\n# Switch to the branch last checked out\ngit checkout -\n\n# Discard changes to a file\ngit checkout -- [file-name.txt]\n\n# Merge a branch into the active branch\ngit merge [branch name]\n\n# Merge a branch into a target branch\ngit merge [source branch] [target branch]\n\n# Merge with a commit message\ngit merge [branch name] -m \"[commit message]\"\n\n# Abort a merge in case of conflicts\ngit merge --abort\n\n# Stash changes in a dirty working directory\ngit stash\n\n# Remove all stashed entries\ngit stash clear\n\n# Apply latest stash to working directory\ngit stash pop\n\n# Check the current branch\ngit branch\n```\n\n### Sharing \u0026 Updating Projects 🔄\n\n```bash\n# Push a branch to your remote repository\ngit push origin [branch name]\n\n# Push changes to remote repository (and remember the branch)\ngit push -u origin [branch name]\n\n# Push changes to remote repository (remembered branch)\ngit push\n\n# Force push changes (use with caution!)\ngit push --force\n\n# Delete a remote branch\ngit push origin --delete [branch name]\n\n# Update local repository to the newest commit\ngit pull\n\n# Pull changes from remote repository\ngit pull origin [branch name]\n\n# Pull changes with rebase instead of merge\ngit pull --rebase origin [branch name]\n\n# Add a remote repository\ngit remote add origin ssh://git@github.com/[username]/[repository-name].git\n\n# Set a repository's origin branch to SSH\ngit remote set-url origin ssh://git@github.com/[username]/[repository-name].git\n\n# Adds a new remote repository with the specified name and URL\ngit remote add \u003cname\u003e \u003crepository_url\u003e\n\n# Lists all the remote repositories associated with the current repository\ngit remote -v\n\n# Remove a remote repository\ngit remote remove \u003cname\u003e\n```\n\n### Inspection \u0026 Comparison 🔍\n\n```bash\n# View changes\ngit log\n\n# View changes (detailed)\ngit log --summary\n\n# View changes (briefly)\ngit log --oneline\n\n# View changes with graph visualization\ngit log --graph --oneline --decorate\n\n# View changes for a specific file\ngit log --follow [file-path]\n\n# Preview changes before merging\ngit diff [source branch] [target branch]\n\n# View unstaged changes\ngit diff\n\n# View staged changes\ngit diff --staged\n\n# View changes between two commits\ngit diff [commit-id-1] [commit-id-2]\n\n# Show what changed in a specific commit\ngit show [commit-id]\n\n# See who modified each line of a file\ngit blame [file-name]\n```\n\n### Git Reset \u0026 Remove Commands ♻️\n\n```bash\n# Unstage your changes in your files\ngit reset\n\n# Unstage a specific file\ngit reset [file-name]\n\n# Unstage your committed changes\ngit reset HEAD^\n\n# Reset to a specific commit (preserves changes as unstaged)\ngit reset [commit-id]\n\n# Reset to a specific commit (discards all changes)\ngit reset --hard [commit-id]\n\n# Almost same to the \"git reset\" but it also gives you the deleted files\ngit reset --hard\n\n# Reset to remote branch state\ngit reset --hard origin/[branch-name]\n\n# Delete and stage the changes in your file\ngit rm filename.extension\n\n# Delete the file forcefully which hasn't been staged\ngit rm filename.extension -f\n\n# Stage the changes and not to delete the file from working directory\ngit rm --cached filename.extension\n\n# Delete a folder recursively\ngit rm -r folder\n```\n\n### Git Push, Fetch, Pull 🔃\n\n```bash\n# Push the local branch to the remote repository\ngit push origin [branch-name]\n\n# Push all local branches to remote repository\ngit push --all origin\n\n# Push tags to remote repository\ngit push --tags\n\n# Download objects and refs from another repository without merging\ngit fetch\n\n# Fetch from all remotes\ngit fetch --all\n\n# Fetch from and integrate with another repository or a local branch\ngit pull\n\n# Fetch and rebase instead of merge\ngit pull --rebase\n\n# Pull from specific remote and branch\ngit pull [remote] [branch]\n```\n\n### Git Stash Commands 📦\n\n```bash\n# Save changes to a temporary area (stash)\ngit stash\n\n# Save changes with a descriptive message\ngit stash save \"Work in progress for feature x\"\n\n# List all stashes\ngit stash list\n\n# Apply the most recent stash without removing it\ngit stash apply\n\n# Apply a specific stash without removing it\ngit stash apply stash@{n}\n\n# Apply and remove the most recent stash\ngit stash pop\n\n# Apply and remove a specific stash\ngit stash pop stash@{n}\n\n# Remove a specific stash\ngit stash drop stash@{n}\n\n# Clear all stashes\ngit stash clear\n\n# Create a branch from a stash\ngit stash branch [branch-name] stash@{n}\n\n# Show the changes in a stash\ngit stash show stash@{n}\n```\n\n### Advanced Git Commands 🧠\n\n```bash\n# Create a lightweight tag\ngit tag [tag-name]\n\n# Create an annotated tag\ngit tag -a [tag-name] -m \"[tag message]\"\n\n# List all tags\ngit tag -l\n\n# Delete a tag\ngit tag -d [tag-name]\n\n# Push a specific tag to remote\ngit push origin [tag-name]\n\n# Push all tags to remote\ngit push origin --tags\n\n# Cherry-pick a commit from another branch\ngit cherry-pick [commit-id]\n\n# Rebase current branch onto another branch\ngit rebase [branch-name]\n\n# Interactive rebase for editing commits\ngit rebase -i HEAD~[number-of-commits]\n\n# Clean untracked files from working directory\ngit clean -n  # Dry run (shows what would be deleted)\ngit clean -f  # Actually delete files\n\n# Clean untracked files and directories\ngit clean -fd\n\n# Bisect to find a bug\ngit bisect start\ngit bisect bad  # Current commit has the bug\ngit bisect good [commit-id]  # Known good commit\n# Git will help you find the commit that introduced the bug\n```\n\n## Git Workflows 🔄\n\n### Basic Git Workflow\n\n1. Initialize repository or clone existing repository\n2. Create a branch for your feature/fix\n3. Make changes to files\n4. Stage changes with `git add`\n5. Commit changes with `git commit`\n6. Push changes to remote with `git push`\n7. Create pull request (on GitHub/GitLab/Bitbucket)\n8. Merge pull request after review\n\n### Feature Branch Workflow 🌱\n\n1. Create a feature branch from main/master\n   ```bash\n   git checkout -b feature/new-feature main\n   ```\n2. Develop the feature with regular commits\n   ```bash\n   git add .\n   git commit -m \"Add new feature component\"\n   ```\n3. Push feature branch to remote\n   ```bash\n   git push -u origin feature/new-feature\n   ```\n4. Create pull request for code review\n5. After approval, merge to main/master\n   ```bash\n   git checkout main\n   git merge feature/new-feature\n   git push\n   ```\n\n### Gitflow Workflow 🌊\n\n1. Maintain two primary branches:\n\n   - `main` or `master` (production code)\n   - `develop` (integration branch)\n\n2. Create feature branches from `develop`\n\n   ```bash\n   git checkout -b feature/new-feature develop\n   ```\n\n3. Create release branches when preparing a release\n\n   ```bash\n   git checkout -b release/1.0.0 develop\n   ```\n\n4. Create hotfix branches from `main` for production fixes\n\n   ```bash\n   git checkout -b hotfix/critical-bug main\n   ```\n\n5. Merge flow:\n   - Features → `develop`\n   - Releases → `main` and `develop`\n   - Hotfixes → `main` and `develop`\n\n## Common Git Problems and Solutions 🛠️\n\n### Reverting a Pushed Commit\n\n```bash\n# Create a new commit that undoes changes\ngit revert \u003ccommit-hash\u003e\ngit push\n```\n\n### Recovering Deleted Branches\n\n```bash\n# Find the SHA of the deleted branch tip\ngit reflog\n\n# Create a new branch at that commit\ngit checkout -b \u003cbranch-name\u003e \u003csha\u003e\n```\n\n### Fixing Merge Conflicts ⚔️\n\n1. Run `git status` to see conflicted files\n2. Open conflicted files and resolve conflicts manually\n3. Look for conflict markers (`\u003c\u003c\u003c\u003c\u003c\u003c\u003c`, `=======`, `\u003e\u003e\u003e\u003e\u003e\u003e\u003e`)\n4. Stage resolved files with `git add \u003cfile\u003e`\n5. Complete the merge with `git commit`\n\n### Undoing a Merge\n\n```bash\n# If the merge is not pushed yet\ngit reset --hard HEAD~1\n\n# If the merge is already pushed\ngit revert -m 1 \u003cmerge-commit-hash\u003e\n```\n\n### Moving Commits to Another Branch\n\n```bash\n# Save current work\ngit stash\n\n# Create or checkout target branch\ngit checkout \u003ctarget-branch\u003e\n\n# Apply commits via cherry-pick\ngit cherry-pick \u003ccommit-hash\u003e\n\n# Return to original branch and drop applied commits\ngit checkout \u003coriginal-branch\u003e\ngit reset --hard \u003chash-before-commits\u003e\n```\n\n## Frequently Asked Questions (FAQ) ❓\n\n### Git Basics\n\n#### Q: What's the difference between Git and GitHub? 🤔\n**A:** Git is a version control system that manages your code history locally. GitHub is a cloud-based hosting service for Git repositories, providing collaboration features like pull requests, issues, and code reviews.\n\n#### Q: Do I need to know command line to use Git? 💻\n**A:** While command line provides the full power of Git, you can use GUI tools like GitHub Desktop, GitKraken, or SourceTree for most common operations without knowing command line commands.\n\n#### Q: How do I undo my last commit? ↩️\n**A:** If you haven't pushed the commit, use `git reset HEAD~1` to undo the commit but keep changes, or `git reset --hard HEAD~1` to completely discard the commit and its changes.\n\n### Repository Management\n\n#### Q: What's the best branching strategy for my project? 🌿\n**A:** It depends on your team size and project needs:\n- Small teams: Feature branch workflow\n- Larger teams with regular releases: Gitflow\n- Continuous deployment: Trunk-based development with feature flags\n\n#### Q: How do I keep my fork updated with the original repository? 🔄\n**A:**\n```bash\n# Add the original repository as an upstream remote\ngit remote add upstream https://github.com/original-owner/original-repository.git\n\n# Fetch the changes\ngit fetch upstream\n\n# Merge the changes into your local branch\ngit merge upstream/main\n```\n\n### Troubleshooting\n\n#### Q: What should I do when I get merge conflicts? ⚠️\n**A:** Merge conflicts happen when Git can't automatically merge changes. To resolve:\n1. Run `git status` to see conflicted files\n2. Edit the files to resolve conflicts (remove conflict markers)\n3. Add resolved files with `git add \u003cfilename\u003e`\n4. Complete the merge with `git commit`\n\n#### Q: I accidentally committed sensitive information, how do I remove it? 🔒\n**A:**\n```bash\n# If not pushed yet, amend the last commit\ngit rm --cached sensitive-file\ngit commit --amend\n\n# If already pushed, you'll need BFG Repo-Cleaner or git-filter-repo \n# and to force push (requires special handling)\n```\n\n### Advanced Usage\n\n#### Q: What's a good commit message format? 📝\n**A:** A good format is:\n```\nfeat(component): add login functionality\n\nImplement user authentication with OAuth2.\nResolves: #123\n```\nElements:\n- Type: feat, fix, docs, style, refactor, test, chore\n- Scope: what part of code is affected\n- Short summary (imperative mood)\n- Optional detailed description\n- Optional references to issues\n\n#### Q: How can I squash multiple commits into one? 🔨\n**A:**\n```bash\n# Interactive rebase to the commit before the ones you want to squash\ngit rebase -i HEAD~3  # To squash last 3 commits\n\n# In the editor, change \"pick\" to \"squash\" for commits you want to combine\n# Save and provide a new commit message\n```\n\n## Additional Resources 📚\n\n- [Official Git Documentation](https://git-scm.com/doc)\n- [GitHub Learning Lab](https://lab.github.com/)\n- [Pro Git Book](https://git-scm.com/book/en/v2)\n- [Git Cheat Sheet by GitHub](https://education.github.com/git-cheat-sheet-education.pdf)\n- [Interactive Git Branching Tutorial](https://learngitbranching.js.org/)\n- [Git Flight Rules](https://github.com/k88hudson/git-flight-rules)\n- [Atlassian Git Tutorials](https://www.atlassian.com/git/tutorials)\n- [Oh Shit, Git!?!](https://ohshitgit.com/) - Practical solutions for common Git mistakes\n- [GitHub Skills](https://skills.github.com/) - Interactive GitHub learning courses\n- [Git Visual Cheat Sheet](http://ndpsoftware.com/git-cheatsheet.html) - Visual representation of Git commands\n\n---\n\nFeel free to contribute to this repository by submitting pull requests or opening issues! 🚀 \n\nIf you found this guide helpful, consider giving it a ⭐ star!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprogrammersiam%2Flearning-git-github-2025","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprogrammersiam%2Flearning-git-github-2025","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprogrammersiam%2Flearning-git-github-2025/lists"}