github commands

...

create ssh keys

1. Check for the SSH keys on your computer

• First, check to see if you already have any SSH keys on your computer. Keys are stored in the .ssh folder. Run 'cd ~/.ssh' in your terminal to nagagate to the .ssh folder.

• If you do not have one in your home (~/) directory, create one and then 'cd' into it.

• Now look at the files in the .ssh folder ⇒ ls -la

• Look for either 'id dsa.pub' or id rsa.pub

• If you have either of the above files skip to step 5, if not go to step 2.

Generate a new SSH key

check your user name & email

Returns what your user name and email (if you have one).

git config --global user.name

check your user name

Run this to see what user name you have set up.

git config --global user.name

set up user name

Set up user name for all repo's.

Example:

git config --global user.name myusername

git config --global user.email

check user email

Run this to see what email address you hae set up.

git config --global user.email

set up user email

Set up user email for all repo's.

Example:

git config --global user.email myemail@email.com

git status

check git status

Run to check the status of your repository, returns any changed, added or deleted files in the selected directory.

git init

create new empty repo

Run to create a new empty git repository in your current directory/folder.

git add

stage for next commit

Add the specified file as its current state to your next commit.

Example:

git add fileOrBranchName

git add.

stage for next commit

Adds all the files in a folder/directory. Great to use for your first commit.

git add -A

stage for next commit

Run to add everything inside the entire directory and stages deleted files for omission as well.

git add --all

stage for next commit

Run to fond all the new and updated files throughout the project and add them to the commit. You can also use the option '-A'.

git commit -m

commit to the repository

Run to commit staged files to the repository, the '-m' allows you to add a message explaining the updates in the commit.

Example:

git commit -m "added contact page"

git push -u origin

push to GitHub

Run to push commit to remote repository (GitHub).

Example:

git push -u origin name-of-branch

git push --all origin

push all committed branches

Run to commit all branches to your remote repository. Used best when setting up initial branch system.

git checkout -b

create & checkout branch

Run to create a new local branch and automatically checks it out. The new branch will be a copy of the branch you were on when you ran the command.

Example:

git checkout -b nameOfNewBranch

git checkout

checkout a branch

Run to checkout an existing branch.

Example:

git checkout nameOfBranch

git merge

merge branches

Run to merge an existing branch to the branch you are currently on.

Example:

First, ensure the branch saved, committed and pushed to your remote repository.

Second, checkout the branch you want to merge onto.

Third, run: git merge branchName

Lastly, commit and push to remote repository.

git branch -a

show all branches

Run to show all existing branches and highlights the branch you are currently on.

git branch -d

delete branch

Run to delete specified branch.

Example:

git branch -d branchName

ssh -T git@github.com

connect to GitHub

Run to connect to your GitHub repository. You will need your passphrase to securely connect.

git clone

clone a remote repo

Clone a remote repository to your local specified directory.

git remote add

origin

add remote repo to...

Run to add a remote repository to your existing local repository and allows you to push code up to the remote repository.

git pull origin

pull code from remote repo

Run to pull code from the remote specified branch and merge it to the current local branch.

Example:

git pull origin remoteBranchName

git remote -v

check remote

Run to return what remote you are working with and the url address.

git remote rm

remove remote branch

Run to remove the remote specified branch.

Example:

git remote rm branchNameToRemove

.gitignor

hide files from remote repo

Run to keep files or entire directories out of the remote repository while still keeping them in your local repository. Add one file or directory per line.

Example:

.gitignor fileOrDirectoryName

git diff

show file changes

Run to show the changes you have made to a file by diffing your local version to the last committed version and returning the code that has been added and deleted. It is good practice to run git diff before you stage a file to commit.

Example:

git diff path/to/file

git push origin

push to remote

Run to push code up to the remote specified branch.

Example:

git push origin branchName

git fetch

download code

Run to download code from a remote repository.

Example:

git fetch nameOfRemoteBranch