Intro to Git/Github – Alanna Burke – March 15, 2016



Intro to Git/Github – Alanna Burke – March 15, 2016

0 0


alannaburke.github.io


On Github AlannaBurke / alannaburke.github.io

Intro to Git/Github

Alanna Burke

March 15, 2016

Your Teaching Assistants Tonight

Tim

Adam

Scott

Sarav

Amber

Getting Started with Git

Git Documentation: http://git-scm.com/doc

The Command Line (CLI)

  • Powerful tool for interacting with computers - and fast!
  • Let's go over some basic commands.

Some Basic Commands

cd

change directory (folder)

ls

list files

la

list all (details of files)

clear

clear the screen

touch [filename]

create an empty filename

mkdir [directoryname]

make an empty folder

GUI Clients

Git is best on the command line, but a GUI client can be useful.

  • Helping to visualize workflow
  • Resolving complex merge conflicts

GUI Clients

Gitk

Should come with git - if not, re-install the latest version and check /usr/local/bin/

GitHub client

Mac: https://mac.github.com/

PC: https://windows.github.com/

SourceTree (my favorite)

http://www.sourcetreeapp.com/

git clone

Clone an existing git repository.

git clone https://github.com/agis-/git-style-guide.git

http://git-scm.com/docs/git-clone

git init

Create a new git repository.

Do this when you want to start developing and you do not yet have a remote repository.

git init

git init

http://git-scm.com/docs/git-init

Let's walk through making & cloning a new repo on http://github.com.

git remote

List your remotes:

git remote -v

Add a remote:

git remote add origin https://github.com/yourusername/yourrepo.git

git remote

http://git-scm.com/docs/git-remote

git branch

Branching is one of the most important parts of source control with git.

Creating a branch allows you to work on the code in your repository in a silo, separate from any other code changes.

git branch [filename or directory]

http://git-scm.com/docs/git-branch

git checkout

Checking out a branch allows you to switch to a different branch, or you can combine the branch and checkout commands to make a new branch and switch to it.

git checkout branchname
git checkout -b branchname

git checkout

Here I checkout the master branch of my project, and then create and checkout a feature branch.

http://git-scm.com/docs/git-branch

The main branch of your repo is called master.

General Git workflow

  • master
  • develop
  • feature branches
  • release branches
  • hotfixes

http://nvie.com/posts/a-successful-git-branching-model/

https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow

git add

Stage files or directories to be committed.

git add [filename or directory]

Stage all modified & added files:

git add .

Stage all modified, added, & deleted files:

git add --all

git add

http://git-scm.com/docs/git-add

git status

Show the status of your current working directory.

git status

http://git-scm.com/docs/git-status

git commit

Commit staged changes to your branch.

git commit -m "I've made these changes"

Commit early and often. Small, self-contained commits are easier to understand and revert when something goes wrong.

http://git-scm.com/docs/git-commit

git reset

Reset staged changes.

Unstage your changes:

git reset

Discard all staged changes:

git reset --hard

http://git-scm.com/docs/git-reset

git push

Push code to your remote repo.

 git push

-u tells the repo to track the "upstream" or remote branch

 git push -u origin branchname

git push

http://git-scm.com/docs/git-push

git pull

Pull one remote branch into a local branch.

http://git-scm.com/docs/git-pull

git fetch

Fetch changes from your remote repository. This will tell your local repo about new branches and any other changes.

git fetch

http://git-scm.com/docs/git-fetch

git merge

Merge one branch into another.

git merge branchname

In everyday development, you're not going to use this much.

git pull actually uses merge, and when you want to merge a branch into master, for example, it's very likely you'll be doing this through the Github interface via a pull request. http://git-scm.com/docs/git-merge