Version control systems track changes to a file or files over time. This means you can:
Also called a 'repo'
A snapshot of the state of a project at a point in time. It includes:
Collaborating with others (and managing your own code/files on GitHub) involves managing these remote repositories - 'pushing' and 'pulling' code from your machine to and from these remotes.
A remote repository, or 'remote', is a version of your project stored on the internet, or a network, or anywhere other than your machine, to which your local repo is linked. This remote repository is often named 'origin.'
Remote
Local
Upstream
Repository
Local
Repository
Index
(Staging)
Workspace
Stash
Working with branches is good! Branches allow you to work away from the main line of development.
It's easy to create a new repo in GitHub. There are two options:
Create a new project in GitHub
~ OR ~
Create a new repo in GitHub as the remote for an existing local project
Forking a repo results in a clone of someone else's repo in your GitHub account. The two remain connected, so you can pull from 'upstream' or send 'pull requests' to the upstream repo.
Your 'fork' of the original repository. A clone of the original repository that lives on GitHub.
The original repository (if applicable)
The local repository on your computer will often have (at least) two remotes: an origin and an upstream.
Pull requests send a message to the 'upstream' asking to merge changes from your repo into theirs. This give the repo owner control over what changes will be accepted, while allowing others to contribute.
Initialize a new local git repository
$ git init starfish
Initialized empty Git repository in /Users/kirschbombe/Sites/
starfish/.git/
$
Add a file to the staging area
$ git add rays.txt
OR
$ git add .
Add files from the staging area to your local repository
$ git commit -m "add rays.txt"
[master (root-commit) f9d6e54] add rays.txt
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 rays.txt
$
Shows the current status of your repository files (unstaged & staged)
$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: rays.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
test.txt
$
$ git rm my-first-file
rm 'my-first-file'
$ git status
On branch my-new-feature
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: my-first-file
$ git mv my-first-file other-name
$ git status
On branch my-new-feature
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
renamed: my-first-file -> other-name
$ git log
commit 5e31a9080c7f0a9b0390cd7dd2aa8e59a28a7328
Author: Yves Laroche <yves.laroche@logicnow.com>
Date: Tue Feb 2 20:02:08 2016 +0000
My first commit
# Short
$ git log --oneline
5e31a90 My first commit
# Limit number of commits
$ git log -10
$ git log --since=1.week
$ git log --after='2016-01-10'
History of commits sent to the repository
$ cat starfish/.gitignore
# Ignore modules, themes, vendors
/core
/modules
/themes
/vendor
# Ignore config files
sites/*/settings*.php
sites/*/services*.yml
# Ignora private files
sites/*/files
sites/*/private
Files that git should ignore
Local
Remote (origin)
pull
push
Remote
Local
Upstream
Repository
Local
Repository
Index
(Staging)
Workspace
Stash
Create a copy of a git repo
$ git clone git@git.bcash.com.br/bcash/api.git
Push commits from local repo to remote repo
$ git push origin master
Downloads the objects and refs (branches & tags) from the remote to the local repo
Fetch does not merge the new commits from the remote.
$ git fetch origin
Imports remote commits to local repo and merges into working directory
$ git pull
git pull is the same as:
$ git fetch origin
$ git merge
Push commits from local repo to the remote
$ git push origin master
Specifies a remote for your local repo to track.
$ git remote add origin https://github.com/kirschbombe/flaneur.git
With the -v argument, it will show a list of existing remotes and their URL.
$ git remote -v
origin https://github.com/kirschbombe/flaneur (fetch)
origin https://github.com/kirschbombe/flaneur (push)
$
List, create, name, and delete branches.
$ git branch develop
Create a new branch named develop
$ git branch
develop
* master
List all branches
Switch to another branch, like the one we just created using git branch
$ git checkout develop
Switched to branch 'develop'
$
Create and switch to a new branch.
$ git checkout -b feature
Switched to a new branch 'feature'
$
The same as git branch feature + git checkout feature
Merge one branch into another
$ git checkout master
To merge the branch "feature" into the branch "master":
$ git merge --no-ff feature
dchildress@library.ucla.edu
@kirschbombe