Urgent.News

What's breaking now, across thousands of outlets.

Tech

# 10 Git Commands That Made Me More Confident With Git

If you've used Git for a while, you probably know the basics: git add git commit git pull git push These commands are enough to get started. But as your projects become bigger and you start working with branches, pull requests, conflicts, and other developers, Git starts getting a little more interesting. Here are 10 Git commands and techniques that I found especially useful for moving beyond the…

Git is a powerful version control system that offers many commands to help developers manage their projects effectively. In this article, we will explore 10 Git commands that can help you become more confident with Git:

1. git merge: This command combines two branches by creating a new merge commit. It is useful when you want to preserve branch history and show that two lines of development were combined.

2. git rebase: Unlike git merge, git rebase moves commits and reapplies them on top of another branch. It creates a cleaner history but should be used carefully, as it rewrites commit history.

3. git commit --amend: If you made a commit and realize you forgot to include something, you can use git commit --amend to add the missing change to the previous commit.

4. git push --force-with-lease: When you have rewritten your local history using commands like rebase, amend, or interactive rebase, you may need to force-push. However, it's safer to use git push --force-with-lease, which checks whether the remote branch has changed before replacing it.

5. git rebase -i: This command allows you to interactively modify the last few commits. You can change the commit message, squash commits together, or drop them entirely.

6. git stash: Sometimes you need to switch tasks but your code isn't ready to commit yet. Git stash helps by temporarily storing your uncommitted changes and giving you a clean working directory.

7. git cherry-pick: When you only need a specific commit from another branch, git cherry-pick is useful. It applies the changes from that commit to your current branch.

8. git reset: This command can move your branch backwards. There are three versions: --soft keeps changes staged, --mixed keeps changes unstaged, and --hard discards the changes.

9. git reflog: If you think you've lost a commit, git reflog can help you recover it. It records movements of references such as HEAD, allowing you to inspect lost commits.

10. git revert: If you pushed a commit to a shared branch that introduced a problem, you can use git revert to create a new commit that undoes the changes made by the original commit.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Build an XRPL Token Screener in About 50 Lines

There are 20,268 tokens issued on the XRP Ledger and only 1,543 of them traded today. A screener is how you tell those two groups apart. Here is a complete one. No dependencies, runs on any Node 18+.

More from Saturday 29 August →