0% found this document useful (0 votes)
9 views2 pages

Git Command Reference Guide

This document provides a comprehensive Git command reference, detailing commands for initializing repositories, managing changes, examining history, collaborating with remote repositories, and undoing changes. It includes commands for configuring settings and offers useful shortcuts and tips for efficient Git usage. Each command is accompanied by a brief description of its function.

Uploaded by

ikramlafer
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Git Command Reference Guide

This document provides a comprehensive Git command reference, detailing commands for initializing repositories, managing changes, examining history, collaborating with remote repositories, and undoing changes. It includes commands for configuring settings and offers useful shortcuts and tips for efficient Git usage. Each command is accompanied by a brief description of its function.

Uploaded by

ikramlafer
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

■ Git Command Reference and Explanations

1. Start a Working Area


Command Description
git init Initialize a new Git repository in the current directory.
git clone <url> Clone an existing remote repository into a new local directory.

2. Work on the Current Change


Command Description
git add <file> Add a file's changes to the staging area.
git mv <old> <new> Rename or move a file or directory tracked by Git.
git restore <file> Restore a file to its last committed version (undo changes).
git rm <file> Remove a file from both the working directory and Git tracking.
git sparse-checkout Manage partial checkouts for large repositories.

3. Examine the History and State


Command Description
git status Show the status of the working directory and staging area.
git diff Display differences between files, commits, or branches.
git log Show the commit history with details.
git show <commit> Show information about a specific commit or object.
git grep <pattern> Search for lines matching a pattern in the repository.
git bisect Find the commit that introduced a bug using binary search.

4. Grow, Mark, and Tweak Your History


Command Description
git branch List, create, or delete branches.
git commit -m "message" Record staged changes with a message.
git merge <branch> Merge another branch into the current one.
git rebase <branch> Reapply commits on top of another branch.
git reset <commit> Reset the current HEAD to a specific commit.
git tag <name> Create a tag (useful for versioning).

5. Collaborate with Remote Repositories


Command Description
git remote add origin <url> Link your local repo to a remote one.
git fetch Download commits and data from a remote repository.
git pull Fetch and merge changes from the remote repository.
git push Upload your commits to the remote repository.

6. Undoing and Restoring


Command Description
git restore <file> Restore a modified file to its last committed version.
git restore --staged <file> Unstage a file (remove it from staging area).
git reset --hard <commit> Completely reset the working directory to a specific commit.
git checkout -- <file> Legacy command to restore a file to its last commit.
git revert <commit> Create a new commit that undoes the changes from a previous commit.

7. Inspect Configuration and Settings


Command Description
git config --list Display all current Git configurations.
git config --global [Link] "Your Name" Set your global Git username.
git config --global [Link] "[Link]@[Link]"
Set your global Git email.
git config --global [Link] auto Enable automatic color in Git output.

8. Useful Shortcuts and Tips


Command Description
git log --graph --oneline --decorate --all Visualize all branches and commits.
git stash Temporarily save uncommitted changes.
git stash pop Restore stashed changes.
git clean -fd Remove untracked files and directories.
git help <command> Get help for a specific Git command.

You might also like