Git Cheatsheet for Everyday Development
Git Cheatsheet for Everyday Development
Git is an essential tool for modern software development. This cheatsheet provides a quick reference for the most common commands you’ll use every day. Whether you’re new to Git or just need a refresher, this guide has you covered.
1. Setup and Initialization
Configure your Git installation and initialize a new repository.
- Configure user name:
git config --global user.name "Your Name"
- Configure user email:
git config --global user.email "youremail@example.com"
- Initialize a new repository:
git init
- Clone an existing repository:
git clone <repository_url>
2. Staging and Committing
Save your changes to the repository.
- Check the status of your files:
git status
- Add a file to the staging area:
git add <file_name>
- Add all changes to the staging area:
git add .
- Commit your staged changes:
git commit -m "Your commit message"
3. Branching and Merging
Work on different features in parallel.
- List all branches:
git branch
- Create a new branch:
git branch <branch_name>
- Switch to a branch:
git checkout <branch_name>
- Create and switch to a new branch:
git checkout -b <branch_name>
- Merge a branch into your current branch:
git merge <branch_name>
- Delete a branch:
git branch -d <branch_name>
4. Remote Repositories
Collaborate with others.
- List remote repositories:
git remote -v
- Add a remote repository:
git remote add <remote_name> <repository_url>
- Fetch changes from a remote repository:
git fetch <remote_name>
- Pull changes from a remote repository:
git pull <remote_name> <branch_name>
- Push changes to a remote repository:
git push <remote_name> <branch_name>
5. Viewing History
Inspect the history of your repository.
- View commit history:
git log
- View commit history with more detail:
git log --oneline --graph --decorate
- View the changes made in a commit:
git show <commit_hash>
Conclusion
This cheatsheet covers the basic Git commands to get you started. Git is a powerful tool with many more features to explore. For more in-depth information, check out the official Git documentation.
Happy coding! 🚀