From charlesreid1

Revision as of 23:51, 17 November 2017 by Admin (talk | contribs) (→‎Scenarios)

Routine Git Operations

Stop Github Asking for Username and Password

If git keeps pestering you for your github username and password, the problem is that all of your repositories are being checked out using their HTTPS url to github. This always requires you to enter your password.

Instead, you should set up your computer to be identified by Github, which will allow you to check out repositories using their GIT url to github. This will be an identical repository, but accessed using a different authentication system (public/private keys over SSH). This is a much more efficient and safe method for authenticating.

The steps:

  • Create your public private key pair
  • Tell Github your public key
  • Change your github repo to use the GIT url and not the HTTPS url

Step 1: Set up Github SSH Keys

Useful instructions: https://help.github.com/articles/generating-ssh-keys

If you don't have a public key, you will need to make one.

If you have one already, your public key is in ~/.ssh/id_rsa.pub so give Github the contents of that file. Log into your Github account, click account settings, and find the SSH Keys option. Add a new SSH key, and copy and paste the contents of ~/.ssh/id_rsa.pub to the box and save the key.

$ cat ~/.ssh/id_rsa.pub

........blah..........

Make sure you don't give Github your private key, which would be a bad idea. Your private key is in ~/.ssh/id_rsa (no pub extension means it is private).

Step 2: Switch Repos from HTTPS to SSH

You can switch your repos from HTTPS to SSL without opening the browser. First check the repo url using the git remote command:

$ git remote -v 
origin   https://github.com/user/repo.git (fetch)
origin   https://github.com/user/repo.git (push)

Find the addresses of the github remotes, and switch the protocol from HTTPS to GIT (note the syntax):

$ git remote set-url origin git@github.com:user/repo.git


Update/Sync a Fork

If you have a fork that has fallen behind the upstream by several commits, here are instructions for how to update it: Git/Sync a Fork

Delete Remote Branch

If you're making multilpe fixes to a remote repository, you might end up creating multiple branches, one for each PR you're submitting. This leaves lots of remote branches laying around. If you want to delete these, here are instructions: Git/Delete Remote Branch

Delete Latest Commits From Master Branch

If you royally fuck things up and commit to the master branch when you did not intend to, git purists will relegate you to the seventh layer of hell.

Don't worry, hope is not lost, here's how you can fix it (quick, before anybody notices!): Git/Delete Commits from Master

Resolving Git Push Conflicts

See Git/Resolving Push Conflicts