DEV Community

Cover image for ๐Ÿ‘จโ€๐Ÿ’ป Git Mastery: Medium-Level Commands to Elevate Your Workflow ๐Ÿš€
Pratik Tamhane
Pratik Tamhane

Posted on • Edited on

๐Ÿ‘จโ€๐Ÿ’ป Git Mastery: Medium-Level Commands to Elevate Your Workflow ๐Ÿš€

1. Fetching Updates: git fetch

Summary: Understand how git fetch retrieves the latest changes from a remote repository without merging them into your current branch. Learn the difference between git fetch and git pull, and how to use fetch to inspect changes before integrating them.

Commands:

git fetch origin
git fetch origin <branch-name>
Enter fullscreen mode Exit fullscreen mode

2. Undoing Changes: git checkout vs. git restore

Summary: Explore how to undo changes in your working directory using git checkout and git restore. Weโ€™ll discuss when to use each command, especially in the context of uncommitted changes.

Commands:

git checkout -- <file-name>
git restore <file-name>
git restore --staged <file-name>
Enter fullscreen mode Exit fullscreen mode

3. Tagging Commits: git tag

Summary: Learn how to use git tag to mark specific commits as milestones in your project. Weโ€™ll cover both lightweight and annotated tags, and how to push tags to remote repositories.

Commands:

git tag <tag-name>
git tag -a <tag-name> -m "Message"
git push origin <tag-name>

Enter fullscreen mode Exit fullscreen mode

4. Deleting Remote Branches: git push --delete

Summary: Discover how to remove obsolete branches from remote repositories using git push --delete. Weโ€™ll also look at how to safely delete local branches that have already been merged.

Commands:

git push origin --delete <branch-name>
git branch -d <branch-name>
Enter fullscreen mode Exit fullscreen mode

5. Creating Aliases: git config alias

Summary: Speed up your workflow by creating custom aliases for your most-used Git commands. Weโ€™ll walk you through setting up simple and complex aliases, making your command line experience more efficient.

Commands:

git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch

Enter fullscreen mode Exit fullscreen mode

6. Interactive Staging: git add -p

Summary: Learn how to use git add -p to stage changes interactively, allowing you to review and selectively add portions of files to your commit. This command is essential for crafting clean, precise commits.

Commands:

git add -p
Enter fullscreen mode Exit fullscreen mode

7. Handling Submodules: git submodule

Summary: Explore how to work with Git submodules to manage dependencies in your projects. Weโ€™ll cover adding, updating, and removing submodules, as well as best practices for working with them.

Commands:

git submodule add <repository-url>
git submodule update --init --recursive
git submodule deinit -f --all
Enter fullscreen mode Exit fullscreen mode

8. Resolving Merge Conflicts: git mergetool

Summary: Discover how to simplify conflict resolution using git mergetool. Weโ€™ll discuss configuring a merge tool, launching it during conflicts, and best practices for resolving complex merges.

Commands:

git mergetool
git config --global merge.tool <tool-name>
Enter fullscreen mode Exit fullscreen mode

9. Saving Commits for Later: git stash save

Summary: Master the use of git stash save to create multiple stashes with custom names, making it easier to manage different work-in-progress changes.

Commands:

git stash save "Work on feature X"
git stash list
Enter fullscreen mode Exit fullscreen mode

10. Cleaning Up Untracked Files: git clean

Summary: Use git clean to remove untracked files and directories from your working directory. Weโ€™ll cover how to safely preview the files to be removed and how to delete them.

Commands:

git clean -n
git clean -f
git clean -fd
Enter fullscreen mode Exit fullscreen mode

Happy coding! ๐Ÿš€

shop Link : https://buymeacoffee.com/pratik1110r/extras

LinkedIn : https://www.linkedin.com/in/pratik-tamhane-583023217/

Behance : https://www.behance.net/pratiktamhane

Top comments (0)