-
Interactive Rebasing:
git rebase -i HEAD~n
- Allows you to squash, edit, reorder, or drop commits interactively. 🔄
-
Rebase with Upstream Changes:
git pull --rebase origin main
- Rebases your local changes on top of the latest changes from the upstream branch. 🌐
- Cherry-Pick a Commit:
git cherry-pick <commit-hash>
- Applies the changes of a specific commit onto your current branch. 🍒
-
Stash Changes:
git stash save "your stash message"
- Temporarily saves your changes without committing them. 📦
-
Apply Stash:
git stash apply stash@{n}
- Applies a specific stash to your working directory. 🧑🎨
-
View Reflog:
git reflog
- Shows a log of all the branch references. 📜
-
Undoing Changes with Reflog:
git reset --hard HEAD@{n}
- Resets the repository to a previous state using the reflog. ⏪
-
Add a Submodule:
git submodule add <repository-url> path/to/submodule
- Adds a submodule to your project. ➕
-
Update Submodules:
git submodule update --recursive --remote
- Updates submodules to the latest commit. 🔄
-
Client-Side Hooks:
- Pre-commit, post-commit, pre-push, etc.
- Located in the
.git/hooks/
directory. 🎣
-
Server-Side Hooks:
- Pre-receive, post-receive, etc.
- Located in the server's repository hooks directory. 🖥️
- Create a Worktree:
git worktree add -b new-branch path/to/new-worktree
- Creates a new working directory and branch to work on simultaneously. 🏗️
-
Commit Small, Logical Units:
- Make commits focused on a single task. 🎯
-
Write Descriptive Commit Messages:
- Clearly communicate the purpose of your changes. 📝
-
Use Branches Effectively:
- Create feature branches for new development.
- Use topic branches for bug fixes. 🌿
-
Regularly Fetch and Pull:
- Keep your local repository up to date. 🔄
-
Keep Repositories Clean:
- Remove obsolete branches.
- Use
.gitignore
to exclude unnecessary files. 🧹
-
Use Git Tags for Releases:
- Tag important commit points for releases. 🏷️
-
Document Your Workflow:
- Provide a README with instructions for setting up and running the project. 📚
-
Collaborate and Communicate:
- Discuss changes with your team before major modifications. 💬
-
Review and Test Before Pushing:
- Avoid pushing code that breaks the build. 🚨
-
Backup Important Branches:
- Regularly back up important branches. 💾