git clone https://github.com/<USERNAME>/<project>.git
cd <project>
git checkout -b dev-feature
git add <filename>
You need to fetch the latest commits from the remote repository without merging them
git fetch origin
After fetching, you can compare your local branch with the remote branch to see which files have changed
git diff --name-only origin/main
If you want to see the actual changes in the files
git diff origin/main
git commit -m "<message>"
git push --set-upstream origin dev-feature
git checkout main
git pull origin main
git merge dev-feature
git push origin main
git branch -d dev-feature
git push origin --delete dev-feature
git checkout main
git fetch origin
git pull origin main
git checkout dev-feature
git rebase main
Manually resolve the conflict in the given file
git add <conflicted-file>
git rebase --continue
git push origin dev-feature
or, if you’ve rebased:
git push origin dev-feature --force
git checkout main
git pull origin main
git checkout main
git pull origin main
git checkout -b dev-newfeatureorbugfix
git reset HEAD <filename>
git reset
To see if your local branch is ahead or behind the remote branch:
git fetch
git status
To see differences between your local branch and the remote branch:
git fetch
git diff origin/main
Replace main with your branch name.
To see commits in your local branch that are not on remote:
git log origin/main..HEAD --oneline
To see commits on remote that are not in your local branch:
git log HEAD..origin/main --oneline
A quick way to check if local and remote are different:
git diff --stat origin/main
git fetch
git diff --name-status origin/main
This will show:
M (Modified files)
A (Added files)
D (Deleted files)
If you only want added or modified files (excluding deletions):
git diff --name-only origin/main
Unstaged changes: Files modified but not staged
git status -s
Or
git diff --name-only
Staged changes: Files added to the staging area:
git diff --cached --name-only
To see which files have changed in commits not pushed to the remote:
git diff --name-status origin/main..HEAD
This shows file differences between your last commit and the remote branch.
If you have modified files but haven't staged them yet, restore them to their last committed state:
git restore <file>
To restore all unstaged changes:
git restore .
If you've already staged changes with git add, but want to unstage them:
git restore --staged <file>
To unstage all files:
git restore --staged .
If you want to completely reset your branch to match the remote:
git reset --hard origin/main
(Replace main with your branch name.)
⚠ Warning: This will delete all local changes, including uncommitted work.
If you've committed but haven’t pushed yet and want to undo the commit but keep the changes:
git reset --soft HEAD~1
If you want to remove the last commit and discard the changes completely:
git reset --hard HEAD~1
If you accidentally deleted a file and want to restore it:
git checkout -- <file>
or
git restore <file>
If you've already pushed a commit and need to undo it:
git revert <commit-hash>
This creates a new commit that undoes the changes, keeping history intact.
If you need to reset your branch to a specific commit:
git reset --hard <commit-hash>
⚠ This will erase commits after the specified commit.