This article offers a quick overview of essential Git commands, organized for easy access.
Getting Started
- Initialize Repository:
git init- Start a new Git repository in the current directory. - Clone Repository:
git clone [URL]- Download an existing repository from a remote source.
Working with Remotes
- List Remotes:
git remote -v- View all remote connections. - Add Remote:
git remote add [name] [URL]- Connect a new remote repository. - Remove Remote:
git remote rm [name]- Delete a remote connection. - Fetch Remote Changes:
git fetch [remote]- Download updates without merging. - Pull Changes:
git pull [remote] [branch]- Fetch and merge changes from a remote branch. - Push Changes:
git push [remote] [branch]- Upload changes to a remote branch.
Branching & Merging
- List Branches:
git branch- See all branches in the repository. - Create Branch:
git branch [name]- Make a new branch. - Switch Branch:
git checkout [name]- Move to an existing branch. - Create & Switch Branch:
git checkout -b [name]- Create and switch to a new branch simultaneously. - Merge Branch:
git merge [branch]- Combine changes from one branch into the current branch. - Delete Branch:
git branch -d [name]- Remove a branch that has been merged.
Making Changes
- Status:
git status- Show the current status of the working directory and staging area. - Add Changes:
git add [file/directory]- Stage changes for the next commit. - Commit Changes:
git commit -m "[message]"- Save changes with a descriptive message. - Amend Commit:
git commit --amend- Edit the most recent commit. - Reset:
git reset [file]- Unstage changes while keeping them in the working directory. - Hard Reset:
git reset --hard [commit]- Reset the current branch to a specific commit, discarding all changes.
Reviewing History
- Log:
git log- Display a list of past commits. - Log (Graph):
git log --graph- View commit history as a graph. - Show Change:
git show [commit]- Show details of a specific commit. - Diff:
git diff [branch]- Compare changes between branches or commits.
Cleanup & Maintenance
- Stash Changes:
git stash- Temporarily save changes without committing. - Apply Stash:
git stash pop- Retrieve stashed changes. - Clean Untracked Files:
git clean -f- Remove files not tracked by Git.
Advanced & Miscellaneous
- Rebase:
git rebase [branch]- Reapply commits on top of another base commit. - Cherry-pick:
git cherry-pick [commit]- Apply a specific commit from one branch onto another. - Tag:
git tag [name]- Create a tag for marking specific points in the commit history. - Search Log:
git log --grep="[pattern]"- Search commit messages for a pattern.

Comments
Post a Comment