Ramblers Documentation

Training for Webmasters

Pushing your changes to GitHub makes your work visible to others and backs up your code in the cloud. This guide will show you how to push your commits from your local branch to the remote repository on GitHub.

What is Pushing?

Pushing sends your local commits to a remote repository (GitHub). It's the opposite of pulling, which downloads changes from the remote repository to your local machine.

  • Local commits exist only on your computer
  • Pushed commits are stored on GitHub and visible to collaborators

Prerequisites

  • A branch with committed changes
  • Git configured with GitHub credentials
  • Network access to GitHub
  • Appropriate permissions to push to the repository

Pushing Your Changes

Step 1: Verify you have commits to push

git status

This should show your branch is ahead of 'origin/branch-name' by X commits.

View unpushed commits:

git log origin/main..HEAD

Step 2: Check your current branch

git branch

Make sure you're on the correct branch before pushing.

Step 3: Push your branch to GitHub

First time pushing a new branch:

git push -u origin feature/my-feature

The -u flag (or --set-upstream) sets up tracking, so future pushes can simply use git push.

Subsequent pushes (after tracking is set up):

git push
Success! After a successful push, you'll see output like:
Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Delta compression using up to 8 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 1.23 KiB | 1.23 MiB/s, done.
Total 6 (delta 4), reused 0 (delta 0)
To https://github.com/CharlieBigley/ra-tools.git
abc1234..def5678 feature/my-feature -> feature/my-feature

Understanding Push Output

What the output means:
  • Enumerating/Counting objects: Git is preparing your commits
  • Compressing: Git is compressing data for efficient transfer
  • Writing objects: Data is being sent to GitHub
  • abc1234..def5678: The range of commits being pushed
  • feature/my-feature -> feature/my-feature: Local branch pushed to remote branch

Common Push Scenarios

Scenario 1: Pushing to a specific remote and branch

git push origin feature/my-feature

This explicitly specifies the remote (origin) and the branch name.

Scenario 2: Pushing all local branches

git push --all origin

This pushes all your local branches to the remote.

Scenario 3: Pushing tags

git push --tags

Or push tags along with commits:

git push --follow-tags

Scenario 4: Force push (use with extreme caution)

git push --force-with-lease

This overwrites the remote branch with your local version. Only use when absolutely necessary.

Warning: Never force push to shared branches like main or develop. This can cause serious problems for other collaborators. Only force push to your own feature branches if needed.

Setting Up Authentication

HTTPS Authentication:

If using HTTPS, you'll need to authenticate:

  • Personal Access Token (recommended): Create one at GitHub Settings > Developer settings > Personal access tokens
  • Use the token as your password when prompted
  • Configure Git to remember credentials:
git config --global credential.helper cache

SSH Authentication:

If using SSH, ensure your SSH key is added to GitHub:

  1. Generate an SSH key: ssh-keygen -t ed25519 -C "This email address is being protected from spambots. You need JavaScript enabled to view it."
  2. Copy the public key: cat ~/.ssh/id_ed25519.pub
  3. Add it to GitHub: Settings > SSH and GPG keys > New SSH key

Checking Remote Configuration

Step 4: View configured remotes

git remote -v

This shows which remote repositories are configured. You should see origin pointing to the ra-tools repository.

Step 5: Check tracking branch

git branch -vv

This shows which remote branch each local branch is tracking.

Working with Forks

If you forked the repository:

Your origin remote points to your fork. You may want to add the original repository as upstream:

git remote add upstream https://github.com/CharlieBigley/ra-tools.git

Then push to your fork:

git push origin feature/my-feature

Verifying Your Push

Step 6: Verify on GitHub

  1. Go to the repository on GitHub: https://github.com/CharlieBigley/ra-tools
  2. Click the "branches" dropdown or "branches" link
  3. You should see your branch listed
  4. Click on your branch to view the commits
Tip: After pushing, GitHub often shows a banner suggesting you create a pull request. This is a convenient way to start the PR process immediately.

Pushing Updates to an Existing Branch

Workflow: Continue working and pushing

# Make changes to files
git add .
git commit -m "Update user validation logic"

# Push the new commits
git push

# Make more changes
git add .
git commit -m "Add error handling"

# Push again
git push

Each push adds your new commits to the remote branch.

What's Next?

After pushing your changes to GitHub, you can:

  • Create a pull request to propose your changes
  • Request code review from maintainers
  • Make additional commits if reviewers request changes
  • Merge your changes into the main codebase

Troubleshooting

Rejected Push - Non-Fast-Forward

If you get a "non-fast-forward" error:

! [rejected] feature/my-feature -> feature/my-feature (non-fast-forward)

This means the remote branch has commits you don't have locally. Solution:

git pull --rebase origin feature/my-feature
git push

Authentication Failed

If authentication fails:

  • For HTTPS: Ensure you're using a Personal Access Token, not your password
  • For SSH: Verify your SSH key is added to GitHub
  • Check your remote URL: git remote get-url origin

Permission Denied

If you get a permission error:

  • Verify you have write access to the repository
  • If working with a fork, make sure you're pushing to your fork, not the original repository
  • Check that you're logged in with the correct GitHub account

Nothing to Push

If Git says "Everything up-to-date":

  • You've already pushed all your commits, or
  • You haven't made any new commits since your last push
  • Verify with: git status

Large Files or Slow Push

If your push is very slow or fails due to large files:

  • Check for accidentally committed large files or binaries
  • Use .gitignore to exclude build artifacts and dependencies
  • Consider using Git LFS (Large File Storage) for large binary files