
Git Command Cheat Sheet for Beginners
Are you new to Git and feeling overwhelmed by the numerous commands? Look no further! This cheat sheet covers the essential Git commands you’ll need to get started with version control.
Basic Commands
Initialize and Clone
git init
Initialize a new Git repository.
git clone [url]
Clone a repository from a URL.
Track Changes
git status
Check the status of your repository.
git add [file]
Stage a file for commit.
git add .
Stage all changes in the repository.
git commit -m "[message]"
Commit changes with a meaningful message.
View History
git log
View commit history.
git log --oneline
View a concise commit history.
Branching
Create and Manage Branches
git branch
List all local branches.
git branch [branch-name]
Create a new branch.
git checkout [branch-name]
Switch to a different branch.
git checkout -b [branch-name]
Create and switch to a new branch.
git merge [branch-name]
Merge changes from another branch.
Remote Repositories
Collaborate with Others
git remote add [name] [url]
Add a remote repository.
git fetch
Fetch changes from a remote repository.
git push
Push changes to a remote repository.
git push -u [remote] [branch]
Push changes and set upstream tracking.
git pull
Pull changes from a remote repository.
Undoing Changes
Fix Mistakes
git reset [file]
Unstage a file.
git reset --hard
Discard all changes and revert to the last commit.
git revert [commit-hash]
Revert a specific commit.
Common Workflows
Create a New Feature
git checkout -b feature/new-feature
- Make changes and commit:
git add .
andgit commit -m "[message]"
- Push changes:
git push -u origin [branch-name]
- Merge changes:
git checkout main
andgit merge [branch-name]
Get Started with Git Today!
With this cheat sheet, you’ll be well on your way to mastering Git and improving your development workflow. Happy coding!