On Github AlannaBurke / alannaburke.github.io
Git Documentation: http://git-scm.com/doc
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
Git is best on the command line, but a GUI client can be useful.
Gitk
Should come with git - if not, re-install the latest version and check /usr/local/bin/
GitHub client
PC: https://windows.github.com/
SourceTree (my favorite)
Clone an existing git repository.
git clone https://github.com/agis-/git-style-guide.git
Create a new git repository.
Do this when you want to start developing and you do not yet have a remote repository.
git init
http://git-scm.com/docs/git-init
Let's walk through making & cloning a new repo on http://github.com.
List your remotes:
git remote -v
Add a remote:
git remote add origin https://github.com/yourusername/yourrepo.git
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]
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
Here I checkout the master branch of my project, and then create and checkout a feature branch.
The main branch of your repo is called master.
General Git workflow
http://nvie.com/posts/a-successful-git-branching-model/
https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow
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
Show the status of your current working directory.
git status
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.
Reset staged changes.
Unstage your changes:
git reset
Discard all staged changes:
git reset --hard
Push code to your remote repo.
git push
-u tells the repo to track the "upstream" or remote branch
git push -u origin branchname
Pull one remote branch into a local branch.
Fetch changes from your remote repository. This will tell your local repo about new branches and any other changes.
git fetch
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