/github-for-non-tech

How to avoid overwriting changes in GitHub?

Discover step-by-step methods to avoid overwriting changes on GitHub. Learn to clone, branch, stash, sync, resolve conflicts, and use pull requests safely.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to avoid overwriting changes in GitHub?

 
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.

  • Open your terminal or command prompt.
  • Navigate to the folder where you want to store the project.
  • Run the clone command:
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.

  • Create a branch with a descriptive name:
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.

  • Edit files in your code editor.
  • Stage changes:
git add .
  • Commit with a clear message:
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.

  • To stash uncommitted changes:
git stash save "WIP: contact page validation"
  • Verify your working directory is clean:
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.

  • Fetch remote branches:
git fetch origin
  • Merge updates into your branch:
git merge origin/main
  • Or, if you prefer a linear history, rebase instead of merge:
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.

  • Open each conflicted file and look for conflict markers:
<<<<<<< HEAD
Your changes here
=======
Their changes here
> >>>>>> origin/main
  • Edit to combine or choose one version, then save.
  • Stage the resolved files:
git add path/to/conflicted-file
  • Continue the merge or rebase:
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.

  • Apply the latest stash:
git stash pop
  • Resolve any conflicts and commit as needed.

 
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.

  • Push your branch to remote:
git push origin feature/my-new-feature
  • Go to the GitHub repository in your browser.
  • Click “Compare & pull request.”
  • Fill in description, assign reviewers, and submit the PR.

 
Step 9: Use branch protection and review process
 

To prevent accidental overwrites on main branches, enable branch protection rules in your GitHub repository settings.

  • Require pull request reviews before merging.
  • Enable status checks (CI builds) to pass before merge.
  • Disallow direct pushes to protected branches.

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.

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022