Christine McClure

The home for my shortcuts, code snippets, and oft-forgotten directions

www.christinemcclure.com

Markdown

Here's a good cheatsheet.

New repo creation - no files

  1. Make repo in GitHub
  2. From computer: git clone git@github.com:camcclure/<repo name>
  3. CD to repo directory
  4. git push origin master

New repo creation - existing files

  1. Make repo in GitHub
  2. CD to project directory
  3. git init
  4. git add .
  5. git commit -m "initial commit"
  6. git remote add origin git@github.com:yourname/<repo name>.git
  7. git push origin master

Branches

Delete local

git branch -D <branch name>

Delete remote

git push origin --delete <branch name>

List all remote and local branches

git branch -a

or:

git fetch

Using Multiple GitHub Accounts

Example: home computer mainly for personal use, sometimes for work use. Set up another account for Galvin login.

  1. Create an SSH key, but instead of accepting the default name of id_rsa, include a tag at the end. I.e. id_rsa_GALVIN
  2. Create or edit ~\.ssh\config Add "-'ssh keyname' to the end of the github line."
  3. Host github.com
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_rsa
    
    Host github-galvin.com
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_rsa_GALVIN
    
  4. Test the new line
  5.   ssh -T git@github-galvin.com
    

When using the secondary account, only need to use the github alias during the initial clone or add origin:

    git remote add origin git@github-galvin.com:galvin/reponame.git
    git clone git@github-galvin.com:galvin/reponame.git

Working in a project team

Starting the project with a fork

Always rebase before you start working to start with the latest version

  1. Initial step: fork repo from original
    or
    clone your existing fork if using a different computer
  2. git remote add upstream git@github-cam.com:<master-repo-userName/repoName>.git

    Note github-cam to identify correct account.

  3. git checkout master // on your branch master
  4. git pull upstream master // from project remote branch master
  5. git checkout dev // on branch dev
  6. git rebase master // on branch dev
  7. < Do work on dev branch, making commits locally >
  8. $ git push origin dev -f // on branch dev (need to force because now your commit numbers will be off from the rebase)
  9. Submit pull request from your branch on GitHub

Editing another coworker's code

  1. Add their project info to your repo:
    git remote add <branch-name-you-will-use:i.e. 'sam'> git://github-cam.com/<their-username/their-projectName>.git

    Note github-cam to identify correct account.

    Using sam for this example.

  2. git fetch sam

    Will see something like:

     * [new branch]      dev        -> sam/dev
     * [new branch]      gh-pages   -> sam/gh-pages
     * [new branch]      master     -> sam/master
    
  3. Check our their working branch onto your own working branch
    git checkout -b sam-dev sam/dev
  4. Make changes and commits.
  5. Push to your version of their branch:
    git push origin sam-dev
  6. From GitHub, select the sam-dev branch and create a pull request going to your coworker's branch. Make sure to use the same branch of theirs (dev) that you pulled from.