lorenrobinsongithubuserguide

18
GitHub User Guide for Windows Loren Robinson Technical Writing Inc. 3/2/2016 Copyright © 2016 Loren Robinson All Rights Reserved

Upload: loren-robinson

Post on 17-Jan-2017

88 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: LorenRobinsonGitHubUserGuide

GitHub User Guide for Windows

Loren Robinson Technical Writing Inc.

3/2/2016

Copyright © 2016 Loren Robinson All Rights Reserved

Page 2: LorenRobinsonGitHubUserGuide

G i t H u b U s e r G u i d e P a g e | 1

GitHub User Guide

Copyright © 2016 Loren Robinson All Rights Reserved.

All rights reserved. Printed in the US. No part of this publication may be produced, distributed, or transmitted in any form or by any means, including photocopying, recording, or other electronic or mechanical methods, without the prior written permission of the publisher, except in the case of brief quotations embodied in critical reviews and other certain noncommercial uses permitted by copyright law.

Printed in the United States

First Printing: 2016

ISBN: 0-1234567-8-9

Loren Robinson Technical Writing, Inc.102 Gold Street Sarasota, FL 34230

Table of Contents1 GitHub at a Glance________________________________________________________________3

GitHub Overview_____________________________________________________________________3

What is Git?________________________________________________________________________3

2 Get Started_______________________________________________________________________4

Sign Up for GitHub__________________________________________________________________4

Copyright © 2016 Loren Robinson All Rights Reserved

Page 3: LorenRobinsonGitHubUserGuide

G i t H u b U s e r G u i d e P a g e | 2

Install Git__________________________________________________________________________4

Set Up Git_________________________________________________________________________5

Caching Your GitHub Password in Git (optional)______________________________________5

Checking for existing SSH Keys____________________________________________________6

Generating a new SSH Key and adding it to the ssh-agent_____________________________6

Adding your SSH Key to the ssh-agent______________________________________________7

Adding a new SSH Key to your GitHub account_______________________________________7

3 How to Use GitHub and Git________________________________________________________9

Creating Your First Repository________________________________________________________9

Make Your First Commit____________________________________________________________10

4 Basic Git Commands_____________________________________________________________12

6 Index____________________________________________________________________________14

1 GitHub at a Glance

GitHub OverviewGitHub is a code sharing and web-based Git repository (also known as a repo) hosting service. A repository is a central place, where data is stored and maintained.

GitHub

Copyright © 2016 Loren Robinson All Rights Reserved

Page 4: LorenRobinsonGitHubUserGuide

G i t H u b U s e r G u i d e P a g e | 3

Provides a web-based graphical interface and desktop and mobile integration. Provides access control and collaboration features, such as bug tracking, feature requests, task

management, and wikis for every project. Lets you work together on projects from anywhere in the world. Provides a backup of your files, gives a visual interface for managing your repos and gives people

a way to navigate your repos. Makes collaboration easy. Offers free and paid plans for private repos, which are usually used to host open source software

projects. Can be used for social networking, and it is the largest host of source code in the world.

It makes contributing to projects easier. Before GitHub, if you wanted to contribute to an open source project, you had to manually download the project’s source code make your changes locally, create a list of changes, called a patch, and then e-mail the patch to the project’s maintainer.

What is Git?Git is a version control software, which means, it manages changes to a project without overwriting any part of that project.

Git

Runs via the command line on your local machine. Works by reading a local repo on your computer and mirroring that code elsewhere, and allows

you to keep track of your files, and the modifications made to those files, in a repo.

Git is mainly used by programmers. However, it can be used by anyone who writes code, and you can use it individually or in a team environment.

Copyright © 2016 Loren Robinson All Rights Reserved

Page 5: LorenRobinsonGitHubUserGuide

G i t H u b U s e r G u i d e P a g e | 4

2 Get Started Sign Up for GitHub

Figure 2:1 GitHub’s Signup page.

The first step is to sign up for a GitHub account. After you enter in the required information, such as your username, email, and password, GitHub will take you to your empty news feed.

Install Git

Figure 2:2 Git Setup Wizard screen.

Download the latest version of Git and install it.

Copyright © 2016 Loren Robinson All Rights Reserved

Page 6: LorenRobinsonGitHubUserGuide

G i t H u b U s e r G u i d e P a g e | 5

Set Up Git

Figure 2:3 Git Bash window

To set up Git, you must make your way to the command line. So, launch the Git Bash application you just installed, not the windows command prompt. Next, tell Git your name, for example:

git config --global user.name "Your Name Here"

For example:

git config --global user.name "John Smith"

Then, you must input your email, and it has to be the same email you used when signing up for GitHub:

git config --global user.email "[email protected]"

Caching Your GitHub Password in Git (optional)You can avoid entering your GitHub credentials each time by using credential helper. It tells Git to remember your GitHub username and password every time it talks to GitHub.

If you clone GitHub repositories, using SSH, then you authenticate, using SSH keys, instead of a username and password. With SSH keys, you can identify trusted computers, without involving passwords. So you must generate an SSH key and add the public key to your GitHub account.

Checking for existing SSH KeysBefore you generate an SSH key, you must check to see if you have existing SSH keys.

Copyright © 2016 Loren Robinson All Rights Reserved

Page 7: LorenRobinsonGitHubUserGuide

G i t H u b U s e r G u i d e P a g e | 6

1 Open Git Bash and enter. And comments start with the hash character # and extend to the end of the line. For example, there are comments listed below:

$ ls -al ~/.ssh# Lists the files in your .ssh directory, if they exist

2 Check the directory listing to see if you already have a public SSH key.By default, the filenames of the public keys are one of the following:

id_dsa.pub

id_ecdsa.pub

id_ed25519.pub

id_rsa.pub

Generating a new SSH Key and adding it to the ssh-agentYou can generate a new SSH key to use for authentication, then add it to the ssh-agent.This is the option you must take if you don't have an existing public and private key pair and don't want to use the ones available to connect to GitHub.

1 Paste the text below in Git Bash, substituting your GitHub email address.$ ssh-keygen -t rsa -b 4096 -C "[email protected]"# Creates a new ssh key, using the provided email as a labelGenerating public/private rsa key pair.

2 When you’re prompted to “Enter a file in which to save the key,” press Enter. This accepts theDefault location. Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]

3 At the prompt, type a secure passphrase. Enter passphrase (empty for no passphrase): [Type a passphrase]Enter same passphrase again: [Type passphrase again]

Adding your SSH Key to the ssh-agentIf you have GitHub for Windows installed, you can use it to clone repositories, rather than deal with SSH keys.

1 Ensure ssh-agent is enabled. And if you are using Git Bash, turn on ssh-agent:

Copyright © 2016 Loren Robinson All Rights Reserved

Page 8: LorenRobinsonGitHubUserGuide

G i t H u b U s e r G u i d e P a g e | 7

# start the ssh-agent in the background$ eval "$(ssh-agent -s)"Agent pid 59566

If you are using another terminal prompt, such as Git for Windows, turn on ssh-agent:# start the ssh-agent in the background$ eval $(ssh-agent -s)Agent pid 59566

2 Add your SSH key to the ssh-agent:$ ssh-add ~/.ssh/id_rsa

Adding a new SSH Key to your GitHub accountTo configure your GitHub account to your new or existing SSH key, you must also add it your GitHub account.

This step comes after checking for existing SSH keys, generating a new SSH Key,and adding it to the ssh-agent.

1 Copy the SSH key to your clipboard. If your SSH key file has a different name than the example code, modify the filename to match your current setup. When copying your key, add no new lines or white spaces.

$ clip < ~/.ssh/id_rsa.pub# Copies the contents of the id_rsa.pub file to your clipboard

2 In the top right corner of any page, click your profile photo then click settings.

3 In the user settings sidebar, click SSH Keys.

4 Click New SSH key.

5 In the “Title” file, add a descriptive label for the new key. For example, if you’re using a personal Chromebook, you might call this key “Personal Chromebook”.

6 Paste your key into the Key field.

7 Click Add SSH key.

8 Confirm the action by entering your GitHub password.

Copyright © 2016 Loren Robinson All Rights Reserved

Page 9: LorenRobinsonGitHubUserGuide

G i t H u b U s e r G u i d e P a g e | 8

3 How to Use GitHub and Git Creating Your First Repository Now, you can use GitHub.

1 Create a repo by clicking on the button that says new repository, on the right side of the account page.

2 Pick a name for your repository.

Copyright © 2016 Loren Robinson All Rights Reserved

Page 10: LorenRobinsonGitHubUserGuide

G i t H u b U s e r G u i d e P a g e | 9

It can be any name. However, it’s best to pick a name you can remember and relates to the name of your project. For example, the figure below uses Hello-World. If you want a longer name, you can add it to the Description (optional) field beneath the Repository name field.

Figure 3.1 GitHub Repository

3 Select a Public or Private Repository.If you are creating an open source project that will have multiple contributions, the best option is a Public Repo. Selecting a Private Repo is a good option if you are working with an individual project or a project with only a couple contributors.

4 Check the box for the initialize this repository with a README. You need to check it, because all repos require a README file. You can write basic information about your project in the README file. After clicking on it, an empty README file will be generated.

5 Click on the button, Create Repository. After clicking the button, create a repo, you can create a repo and add code.

Make Your First Commit

You commit files when you send them to GitHub.

1 Open the command prompt for Window Users.

2 Create a directory.

Copyright © 2016 Loren Robinson All Rights Reserved

Page 11: LorenRobinsonGitHubUserGuide

G i t H u b U s e r G u i d e P a g e | 10

mkdir ~/Hello-World

Create a directory and give the directory a relevant name to the project. The directory listed in the image above is named Hello-World.

3 Change the Directory.

cd ~/Hello-World

You can change to the directory, using the cd, the change directory command. The ~ represents your home directory in Git Bash and Terminal.

4 Create a file.

touch README

You need to create a file, so you have something to commit. If you already have a repo completed, then CD to that directory and then run the git init command. If you have no file, run the command above to create a README file. Run the ls command, and that will show a list of everything in the current directory.

5 Commit the File.

git add README

Type git add and README listed above to commit it. You can add additional files to commit by using the same command. But, replace README with the name of the different file.

The word Git is telling the command line you want to use the Git program. Commit states you want to use the commit command. –M means message and between ‘first commit’ you can write a message, which is optional. The message is a good reference for the different versions of files you commit.

6 Next, Push the File to GitHub.

git remote add origin https://github.com/yourusername/Hello-World.git

Copyright © 2016 Loren Robinson All Rights Reserved

git commit -m 'first commit'

Page 12: LorenRobinsonGitHubUserGuide

G i t H u b U s e r G u i d e P a g e | 11

You can officially push the file to GitHub with the above commands. You write in your username, where it says username above.

git remote add origin https://github.com/githubproject2025/Hello-World.git

Then, you can send it with the commands displayed above.

That’s it. The file is officially on GitHub. You can do this as you make updates to the file, so the other contributors on the project can see your work.

4 Basic Git CommandsListed below is a reference of the Basic Git Commands.

Git Command Function

git init Create a new local repository.git clone/path/to/repository Clone a repository into a new directory.git clone username@host:/path/to/repository Clone a repository into a new directory, for a

remote server user.git add <filename> Add Files.git commit –m “Commit message” Commit.git commit –a Commit files you added with git add.git push origin master Push and send changes to master branch remote

repository.

Copyright © 2016 Loren Robinson All Rights Reserved

Page 13: LorenRobinsonGitHubUserGuide

G i t H u b U s e r G u i d e P a g e | 12

git status Status.git remote add origin <server> Connect to a remote repository.git remote –v List all configured remote repositories.git checkout –b <branchname> Create a new branch and switch to it.git checkout <branchname> Switch to a different brand.git branch Lists the branches and tells what branch your in.git branch –d <branchname> Deletes the feature branch.git push origin <branchname> Push the branch to your remote repository.git push -- all origin Push all branches to your remote repository.git push origin :<branchname> Delete a branch on your remote repository.git pull Fetch and merge changes on the remote server to

your working directory.git merge <branchname> Merge a different branch into your active branch.git diff View all the merge conflicts.git diff --base <filename> View the conflicts against the base file.git diff <sourcebranch> <targetbranch> Preview changes before merging.git tag 1.0.0 <commitID> Mark a significant changeset, such as a release.git log Shows commit logs.git push --tags origin Push all tags to remote repository.git checkout -- <filename> Switch branches or restore working tree files.git fetch Download objects and commits from another

repository.git grep Print lines matching a pattern.

5 Table of Links and Resources

.

Copyright © 2016 Loren Robinson All Rights Reserved

Page Name URLAtlassian Documentation Git Resources https://confluence.atlassian.com/bitbucketserver/git-

resources-776639766.htmlGitHub Help https://help.github.com/Git –everything-is-local Reference https://git-scm.com/docsGitHub Guides https://guides.github.com/

Page 14: LorenRobinsonGitHubUserGuide

G i t H u b U s e r G u i d e P a g e | 13

6 Index

Command Line 3,5,11

Commit 10-13

Directory 6,10,12,13

Git 3,4,5,9,11-14

Git Bash 5,6,7,10

Git Commands 12,13

Copyright © 2016 Loren Robinson All Rights Reserved

Page 15: LorenRobinsonGitHubUserGuide

G i t H u b U s e r G u i d e P a g e | 14

GitHub 3-11,14

Repository 3,9-12,13

ssh-agent 6,7

SSH Key 5-8

Copyright © 2016 Loren Robinson All Rights Reserved