git remote set-url

This is for all my DevMountain cohort members - compare your GitHub Contributions graphic (i.e. github.com/your_username) to mine - https://github.com/metasean . See all those greenish blocks on the right-hand side of my contributions graphic? If you don’t have a lot of those green blocks, then this post is for you!

Background

First, some background. In my opinion, if you make a git commit and push it to GitHub, then I think you should automatically get credit for it. Unfortunately, if you did a fork of someone else’s project then - by default - you don’t get credit for pushing changes to your own GitHub. The good news is twofold - first, it’s easy to get credit for a repo; second, you get credit based on the date of the git commit not the day you push it to GitHub. So, if you’ve done git commits on a somewhat regular basis, you can retroactively fill in your contributions graphic! :-)

The key to getting credit is to:

  1. Manually create a new repo from your GitHub account.
  2. Run the command git remote set-url origin plus the new repo’s url (use the ssh version if you have it set up) to reset your local git repository’s origin to your new GitHub repo.
  3. git add, git commit, and git push as you normally would.

Bonus Tip: gh-pages

If your repo contains just html, css, and vanilla javascript (i.e., it doesn’t require a database backend or server of any sort), then you can create a gh-pages branch and link directly to the rendered result.

For example, week one we worked on html and css challenges. A standard GitHub link for the html of our ‘html-css-assessment’ project would lead you to a page like - https://github.com/metasean/html-css-assessment/blob/master/index.html. BUT, by making a partner gh-pages branch I can link to a version that renders my page as html instead of just showing the raw html - http://metasean.github.io/html-css-assessment/index.html.

Note the url diffences:

  • standard GitHub link (i.e. shows the source code):
    https://github.com/username/repo_name/path/to/file.ext
  • ‘gh-pages’ link (i.e. rendered result of a non-server html page):
    http://username.github.io/repo_name/file.ext

Cheatsheet

With the background out of the way, the following ‘cheatsheet’ should help you rapidly update your own GitHub repos, so that you get more GitHub credit for your hardwork!

  1. From your GitHub account, create a new repo (or delete the existing one and recreate it).
  2. git remote set-url origin git://new.url.here
    Replace git://new.url.here with the GitHub generated link.
    This is the magic sauce command ;-)
    If you’ve already done your adds and commits, you can skip straight to step 5!
  3. git add .
    Remember that git add . will add everything in the directory that isn’t listed in the ‘.gitignore’ file, so adjust this command as appropriate for your needs
  4. git commit -a -m "commit message"
    Commit all the modified and added files. Obviously, adjust the commit message as appropriate.
  5. git push origin master
    Push to the new origin repo.
  6. git checkout -b gh-pages
    Create, and move to, a new ‘gh-pages’ branch.
  7. git push origin gh-pages
    Push to the ‘gh-pages’ branch.

Results

If you’ve been making somewhat regular git commits, but haven’t been getting your GitHub credit, it should only take you a few minutes of setting ‘git remotes’ and pushing to the new origin to remedy the contributions void!