Discover step-by-step methods to avoid overwriting changes on GitHub. Learn to clone, branch, stash, sync, resolve conflicts, and use pull requests safely.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Step 1: Clone the repository and set up your local environment
Before making any changes, ensure you have a local copy of the repository. This prevents accidental edits on the remote directly.
git clone https://github.com/username/repository.git
cd repository
Step 2: Create and switch to a new branch
Working on a dedicated branch isolates your work and reduces the risk of overwriting others’ changes on the main branch.
git checkout -b feature/my-new-feature
Step 3: Make changes and commit regularly
Committing often helps you track progress and revert if something goes wrong. Each commit is a logical unit of change.
git add .
git commit -m "Add form validation to contact page"
Step 4: Stash or commit your local changes before pulling
If you have uncommitted work, stashing saves it temporarily so you can safely pull updates without overwriting.
git stash save "WIP: contact page validation"
git status
Step 5: Synchronize your branch with remote updates
Always fetch and merge (or rebase) remote updates before pushing. This ensures your branch includes the latest changes.
git fetch origin
git merge origin/main
git rebase origin/main
Step 6: Resolve merge conflicts if they occur
Conflicts happen when the same lines were edited in both branches. Git will mark conflicts in affected files.
<<<<<<< HEAD
Your changes here
=======
Their changes here
> >>>>>> origin/main
git add path/to/conflicted-file
git commit -m "Resolve merge conflicts"
# or, if rebasing
git rebase --continue
Step 7: Reapply stashed changes (if you used stash)
If you stashed earlier, now you can bring those changes back into your working directory.
git stash pop
Step 8: Push your branch and open a Pull Request
Submitting your work as a pull request on GitHub lets team members review and merge safely.
git push origin feature/my-new-feature
Step 9: Use branch protection and review process
To prevent accidental overwrites on main branches, enable branch protection rules in your GitHub repository settings.
By following these steps—working on feature branches, committing frequently, stashing before pulls, syncing with fetch
+merge
or rebase
, resolving conflicts carefully, and using pull requests with branch protection—you safeguard your work and avoid overwriting others’ changes in GitHub.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.