Welcome to the world of Git, a powerful version control system that keeps your project organized and collaboration smooth. Below is a professional Git cheat sheet to help you navigate Git with ease, including the git commit --amend
feature and some examples of good commit messages.
-
Install Git 📦
- Download and install Git from git-scm.com.
-
Configure Your Identity 👤
- Set your name:
git config --global user.name "Your Name"
- Set your email:
git config --global user.email "[email protected]"
- Set your name:
-
Initialize a Repository 🚀
- Create a new Git repository:
git init
- Create a new Git repository:
-
Clone a Repository 🧬
- Clone an existing repository:
git clone <repository URL>
- Clone an existing repository:
-
Check Status 🧐
- View the status of your working directory:
git status
- View the status of your working directory:
-
Add Files ➕
- Stage changes for commit:
git add <filename>
orgit add .
(for all changes)
- Stage changes for commit:
-
Commit Changes 💬
- Commit staged changes with a descriptive message:
git commit -m "Your commit message"
Example Commit Messages:
feat: Add user registration functionality
fix: Resolve issue with login page
chore: Update dependencies
docs: Improve API documentation
style: Format code according to style guide
refactor: Reorganize project structure
test: Add unit tests for authentication
- Commit staged changes with a descriptive message:
-
Amend Commits with Vim ✍️
-
Edit the last commit message and changes interactively:
git commit --amend
This command opens the Vim text editor, allowing you to modify the commit message. Here's how to use Vim:
- Press
i
to enter insert mode. You can now make changes to the text. - Use the arrow keys to navigate to the part of the commit message you want to edit.
- After making your edits, press
Esc
to exit insert mode.
To save your changes:
- Type
:w
and pressEnter
. This tells Vim to write (save) the changes. - To exit Vim:
- Type
:q
and pressEnter
if you haven't made any changes you want to save. - Type
:wq
and pressEnter
to save and exit Vim if you've made changes.
- Type
Remember, Vim has a learning curve, but it's a powerful text editor once you get the hang of it.
- Press
Make sure to follow these steps to successfully save your changes and exit Vim.
-
-
Create a New Branch 🌱
- Start a new branch:
git branch <branch-name>
- Switch to a branch:
git checkout <branch-name>
- Start a new branch:
-
Merge Branches 🤝
- Merge a branch into the current branch:
git merge <branch-name>
- Merge a branch into the current branch:
-
Delete Branch ❌
- Delete a branch (locally):
git branch -d <branch-name>
- Delete a branch (remotely):
git push origin --delete <branch-name>
- Delete a branch (locally):
-
View Commit History 📜
- Review commit history:
git log
- Review commit history:
-
Time Travel ⏳
- Check out a specific commit:
git checkout <commit-SHA>
- Check out a specific commit:
-
Remote Repositories 🌐
- Add a remote repository:
git remote add origin <repository URL>
- Add a remote repository:
-
Pull Requests 🙏
- Create and review pull requests on platforms like GitHub or GitLab.
-
Resolve Conflicts 🔥
- Address merge conflicts collaboratively.
-
Reset Commits 🔄
- Uncommit local changes:
git reset HEAD~1
- Uncommit local changes:
-
Revert Changes ↩️
- Create a new commit to undo previous changes:
git revert <commit-SHA>
- Create a new commit to undo previous changes:
-
Stash Changes 📦
- Temporarily save changes for later:
git stash
- Temporarily save changes for later:
-
Aliases 🐇
- Set up command shortcuts:
git config --global alias.<alias-name> "<git-command>"
- Set up command shortcuts:
-
Interactive Rebase 🧩
- Reorder, squash, and edit commits interactively:
git rebase -i <base-branch>
- Reorder, squash, and edit commits interactively:
-
.gitignore 🙅
- Create a .gitignore file to specify files and directories to be ignored by Git.
Stay organized, collaborate effectively, and make the most of Git's capabilities in your projects. Git is a powerful tool when used proficiently. Happy coding! 🚀👩💻👨💻