Skip to content

A beginner-friendly, comprehensive Git tutorial repository with clear explanations and practical examples for essential Git commands. Perfect for developers who want to master Git step-by-step.

License

Notifications You must be signed in to change notification settings

BaseMax/LearnMoreGit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

LearnMoreGit

Welcome to LearnMoreGit, a comprehensive guide to Git commands with clear explanations and practical examples. This README covers essential Git commands for beginners and intermediate users, focusing on real-world usage and understanding.

Table of Contents (Learn Git)


Git Configuration (git config)

git config is used to configure Git settings such as user information, proxy settings, and signing keys. These settings help Git identify who is making commits and control other behaviors.

Common commands:

git config --global user.name "UserName"

Set your Git username globally (used in commits).

git config --global user.email "Email"

Set your email globally.

git config --global user.signingkey sec

Set your GPG key for signing commits.


Initialize a Git Repository (git init)

Starts a new Git repository by creating a .git directory (hidden on Unix-based systems).

Examples:

git init

Initialize Git repo in current directory.

mkdir MyProject
cd MyProject
git init

Create a new directory and initialize a Git repo inside.


Adding Files to Git (git add)

Stages files to be committed.

Examples:

git add fileName

Add a single file to the staging area.

git add -A

Add all files (tracked and untracked) to staging.

git add .

Add all files in the current directory and subdirectories.


Viewing Commit History (git log)

Shows the commit history.

Examples:

git log

Show full commit history with details.

git log --oneline -5

Show the last 5 commits in a simplified one-line format.


Commit Changes (git commit)

Save staged changes with a message.

Examples:

git commit -m "Title"

Commit with a short message.

git commit -m "Title" -m "Description"

Commit with a title and longer description.

git commit -am "Title"

Commit tracked files with changes without git add.


Check Repository Status (git status)

Shows the current state of the working directory and staging area.

git status

Clean Untracked Files (git clean)

Remove untracked files from working directory.

git clean -f

Remove untracked files (use -f to force).


Unstage a File (git reset)

Remove files from the staging area.

git reset fileName

Show Differences (git diff)

Show changes between working directory, staging area, and commits.

Examples:

git diff HEAD

Show changes since last commit.

git diff --staged

Show staged changes.

git diff branchName

Show difference between current branch and another branch.


Revert Changes (git checkout and git reset)

Restore files or move HEAD pointer.

Examples:

git checkout -- fileName

Revert file to last committed state.

git reset commitHash

Move HEAD to a specific commit, unstaging changes.

git reset --hard commitHash

Move HEAD and discard all changes.


Branching (git branch and git checkout)

Manage branches.

Examples:

git branch

List branches.

git branch branchName

Create a new branch.

git checkout -b branchName

Create and switch to new branch.

git checkout branchName

Switch to an existing branch.


Merge Branches (git merge)

Merge changes from another branch into the current branch.

git merge branchName

Remove Files (git rm)

Remove files from Git and filesystem.

git rm fileName

Restore file after accidental remove:

git checkout HEAD fileName

Delete or Rename Branch (git branch)

git branch -d branchName

Delete branch.

git branch -M branchName

Rename branch (commonly used to rename default branch to main).


Push and Pull (git push and git pull)

Synchronize with remote repositories.

git push origin master

Push master branch to remote origin.

git pull origin master

Fetch and merge master branch from remote.


Manage Remotes (git remote)

Manage remote repositories.

git remote

List remotes.

git remote add origin url

Add a new remote named origin.

git remote remove remoteName

Remove a remote.

git remote rename oldName newName

Rename a remote.


Show Commit or Tag Details (git show)

git show commitID

Show details of a specific commit.

git tag

List tags.

git tag -a tagName -m "description"

Create an annotated tag.

git show tagName

Show tag details.


View File History (git blame)

Show line-by-line author info.

git blame fileName -L startLine,endLine

Show authorship info for a range of lines.


Debug with Bisect (git bisect)

Find the commit that introduced a bug.

git bisect start
git bisect bad
git bisect good commitHash

Bisect between good and bad commits.

git bisect reset

Stop bisect and return to original state.


Stashing Changes (git stash)

Save uncommitted changes temporarily.

git stash
git stash list
git stash pop stash@{0}

Clone Repository (git clone)

Copy remote repository locally.

git clone repositoryAddress

Cherry-pick Commits (git cherry-pick)

Apply a commit from another branch to the current one.

git cherry-pick commitHash

Summary

This README provides fundamental Git commands and practical examples to help you get started and manage your projects efficiently. For detailed help, use git help <command> or visit the official Git documentation.

Happy Git learning! 🚀


Created by Max Base

About

A beginner-friendly, comprehensive Git tutorial repository with clear explanations and practical examples for essential Git commands. Perfect for developers who want to master Git step-by-step.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published