tags:

  • software

Do git bash here.

git status

git add . (adds all)

git status

git commit -m ""

git push

Notes

https://www.youtube.com/watch?v=xnR0dlOqNVE

Git Fork vs. Git Clone

How to do git commit messages properly

Examples

Git: Common Issues and Fixes

Git can be frustrating, especially when things go wrong. This guide provides practical solutions to common Git mistakes, explained in simple terms.

https://ohshitgit.com/

🔄 Undoing Mistakes

I messed up badly! Can I go back in time?

Yes! Use Git’s reflog to find a previous state:

git reflog
# Find the index of the state before things broke
git reset HEAD@{index}

This is useful for recovering deleted commits, undoing bad merges, or rolling back to a working state.

🚀 Commit Fixes

I committed but forgot a small change!

# Make the change
git add .
git commit --amend --no-edit

⚠ Warning: Never amend a commit that has already been pushed!

I need to change the last commit message!

git commit --amend

This will open an editor where you can modify the commit message.

🔀 Branching Issues

I committed to master but wanted a new branch!

# Create a new branch from the current state
git branch new-branch
# Remove the commit from master
git reset HEAD~ --hard
git checkout new-branch

⚠ Warning: If you’ve already pushed the commit, additional steps are needed.

I committed to the wrong branch!

# Undo the last commit but keep the changes
git reset HEAD~ --soft
git stash
git checkout correct-branch
git stash pop
git add .
git commit -m "Moved commit to correct branch"

Alternative:

git checkout correct-branch
git cherry-pick master  # Moves last commit to correct branch
git checkout master
git reset HEAD~ --hard  # Removes the commit from master

🔍 Diff and Reset

I ran git diff, but it showed nothing!

If your changes are staged, use:

git diff --staged

This shows differences between the last commit and staged files.

I need to undo a commit from 5 commits ago!

git log  # Find the commit hash
git revert [commit-hash]

This creates a new commit that undoes the changes.

🗑️ Undoing Changes

I need to undo changes to a file!

git log  # Find a commit before the changes
git checkout [commit-hash] -- path/to/file
git commit -m "Reverted file to previous version"

I want to reset my repo to match the remote!

Destructive action—this cannot be undone!

git fetch origin
git checkout master
git reset --hard origin/master
git clean -d --force  # Removes untracked files

🤯 Last Resort

If everything is completely broken, nuke the repo and reclone:

cd ..
sudo rm -r repo-folder
git clone https://github.com/user/repo.git
cd repo-folder