This guide walks you through the complete workflow for pulling a repository, making changes, and pushing them back up to GitHub.
Step 1: Clone the repository
First, get a local copy of the repository on your computer.
git clone https://github.com/username/repository-name.gitThen, move into the newly created folder:
cd repository-nameStep 2: Create a new branch
It's highly recommended to work on a separate branch instead of editing the main branch directly. This keeps your changes organized and safe.
git checkout -b your-branch-nameExample:
git checkout -b new-branchStep 3: Make your edits
Now you can open the project in your favorite code editor and start making changes.
nvim .Go ahead and edit files, add new ones, or delete old ones.
Step 4: Stage and commit your changes
Once you're happy with your edits, you need to "stage" them (prepare them for saving) and then "commit" them (save them with a message).
1. Stage all changes:
git add .2. Commit the staged changes with a clear message:
git commit -m "Describe what you changed"Step 5: Push your branch to GitHub
Now, send your new branch (with your commits) up to the remote repository on GitHub.
git push origin new-branchStep 6: Create a pull request (PR)
This is the standard way to merge your changes into the main branch.
- Go to the repository page on GitHub.
- You will see a notification with your new branch name and a button that says "Compare & pull request".
- Click it, review your changes, add a title and description, and submit the pull request.
- Once approved (by you or a teammate), you can merge it.
Alternative (not recommended for teams): If you have direct write access and are sure, you could push directly to
main, but using branches and pull requests is much safer and better practice.
Step 7: Keep your repo in sync
If other people are working on the same repository, their changes might get merged into main. Before you start new work, always pull the latest changes to avoid conflicts.
First, switch back to your main branch:
git checkout mainThen, pull the latest updates:
git pull origin main
Comments
Loading the discussion…