Overview
After making changes locally, you need to push them to a remote repository to share your work or back it up.
Steps
- Stage your changes for commit:
git add . # Adds all modified files
# or
git add filename # Adds specific file
- Commit your changes with a descriptive message:
git commit -m "Brief description of your changes"
- Push your commits to the remote repository:
git push origin branch-name
Common Issues
- Rejected push: The remote branch has changes you don’t have locally. Perform a
git pull
first - Authentication failed: Ensure your credentials are correct; consider using SSH or a personal access token
- New branch not appearing on GitHub: For a new branch, you may need to set upstream tracking:
git push -u origin branch-name
Additional Notes
- Always pull before pushing to avoid conflicts
- Use meaningful commit messages that explain why the change was made
- If you’ve created a branch locally, you need to push it to make it visible remotely
Making Changes Directly on GitHub
Instead of pushing local changes, you can make simple edits directly on GitHub:
- Navigate to the repository and file you want to edit
- Click the pencil icon (Edit this file)
- Make your changes in the editor
- Scroll down to the “Commit changes” section
- Add a commit message describing your changes
- Choose whether to commit directly to the current branch or create a new branch and pull request
- Click “Commit changes”
This is useful for small changes but lacks the power of a local development environment.