Skip to content

Instantly share code, notes, and snippets.

@obar1
Created September 30, 2025 11:38
Show Gist options
  • Save obar1/06c8292ce9c756c33ab95288e89ebeb8 to your computer and use it in GitHub Desktop.
Save obar1/06c8292ce9c756c33ab95288e89ebeb8 to your computer and use it in GitHub Desktop.
git-me a bit

Beginner-Friendly Git Guide

Git is a version control system that helps developers track changes in their code and collaborate with others. This guide introduces common Git commands and workflows for beginners.

1. git init

Initializes a new Git repository in your project folder. Example: git init

2. git clone

Copies an existing Git repository from a remote server (like GitHub) to your local machine. Example: git clone https://github.com/user/repo.git

3. git add

Stages changes to be committed. You can add specific files or all changes. Examples: git add filename.txt git add .

4. git commit

Saves the staged changes to the repository with a message describing the changes. Example: git commit -m "Add new feature"

5. git push

Uploads your local commits to the remote repository. Example: git push origin main

6. git pull

Downloads changes from the remote repository and integrates them into your local branch. Example: git pull origin main

7. git rebase

Reapplies your local commits on top of the latest changes from the remote branch. This keeps history clean. Example: git pull --rebase origin main

8. Resolving Push Rejections

If you see an error like: ! [rejected] main -> main (fetch first) It means the remote branch has changes you don't have locally. To fix this: git pull --rebase origin main git push origin main

9. Set Git to Automatically Rebase on Pull

To make Git always rebase when pulling: git config --global pull.rebase true

When to Use 'git pull' with Merge Instead of Rebase

While 'git pull --rebase' is useful for maintaining a clean and linear commit history, there are several scenarios where using 'git pull' with merge is a better choice:

  1. Collaborative Feature Branches: When multiple contributors are working on the same branch, rebasing can rewrite history and cause confusion. Merging preserves everyone's commit history and avoids conflicts.
  2. Tracking History for Debugging: Merge commits help retain the exact sequence of events, which is useful for auditing and debugging complex workflows.
  3. CI/CD Pipelines or Release Branches: Merges clearly show integration points, which are important for deployment and release tracking.
  4. Conflict-Prone Histories: If frequent conflicts are expected, merging may be easier to manage than rebasing, which applies commits one by one.
  5. You're Not Comfortable with Rebase Yet: Beginners may find merge easier to understand and safer to use until they are confident with resolving rebase conflicts.

Decision Table: When to Use Merge vs Rebase

Git Workflow Overview

Rebase vs Merge

Git Pull Scenarios

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment