Github
Install Git on A Mac
http://git-scm.com Download and Install, then go to terminal and type
git --version
Install Git on Windows
Same as mac, but you have to use the git terminal
Basic Principle of Git
- Make changes to website content
- Add The changes // git add ??
- commit changes // git commit ??
Getting Started with a Git Project
- Identify a folder project
- CD into Project Directory
- In the git Terminal enter
git init
Add files to the Staging Environment
git add . git status // will give you the status
Committing Files
This saves the state of the files at a specific time
get commit -m "whatever you want to say"
This does NOT create a branch just a state which you can get to by running:
git log // will list all log entries git log -n2 // will list the last 2 entries git log --since=2012-06-15 // git log --author="kevin" git log --grep="init" // will search for "init"
Edit Global File
git config --global --edit vi commands i // for insert Esc key :wq // saves the file
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
Other git Commands
git log git checkout about.html// this will revert the previous version in staging or if you delete a file it will bring it back * the git checkout is like an undelete if you want to commit the deleted file to staging git add about.html
Delete a file from project and also from staging
git rm about.html
Unstage changes after reset
git reset HEAD about.html // pulls it out of archive and puts it back into staging git checkout about.html // restores the file
Its a 2 step process, because staging is like undo and the archive is pulling the saved version and putting it back into undo
Process many changes to staging
if you modified files and delete files and did a lot of changes you can issue
git add --all // this will take care of all modifications
Working with different commits
git log // this will show you all the commits git checkout 9bf8c5934dc294fe21cf0cb2bb9e89afb711af62 // the commit hash
This will restore this commit, but it will be in a alternate branch the original branch is the master branch and you can go back an restore the last master commit
Switch back to master branch
git checkout master
Create another branch from previous commits
git branch nameofbranch hashcode of previous commit
Switching between branches will restore the files that was committed in that branch
Using Stash
Temporary storage place, you don't need to commit in order to switch between branches
git stash save "Information about change"
List items in stash
git stash list
Get info on a particular stash
git stash show -p stash@{0}
Get items out of the stash
Switch to the branch you want to be in
git stash pop stash@{0}// this will retrieve it from the stash into the current working branch then delete it from the stash git stash apply // will leave a copy in the stash
Delete items from the stash
git stash drop stash@{0}
OR
git stash clear // will delete all stashes
Working With Remote Github
Push an existing repository from the command line
git remote add Anyname url // see below for exact syntax git remote add origin https://github.com/bacchas1/repositoryname.git // this url can be found by clicking the clone or download button git push -u origin master // master is the branch, origin is the alias
Make sure you are on the branch you want to push
git remote -v // info on remote git branch -r // shows you remote branch git branch -a // shows you both remote and local
The remote info is stored in the .git/config file
Remove a Remote from local project
git remote rm origin
Cloning a Repository from GitHub
get the clone url from github, then issue command below
git clone https://github.com/planetoftheweb/responsive.git
When it clones it only clones the master branch but you can view the other branches
git branch -a
to get any other branch:
git checkout -b localnameForBranch location/nameofbranch/
- eg. remotes/origin/02_08
So to get that branch:
git checkout -b localName origin/02_08
Cloning a Repository with all its braches
- First Create a Directory for the project
- switch to that directory
git clone --mirror https://github.com/planetoftheweb/responsive.git .git
It will download a hidden .git file with all the repositories, to convert it to a regular Repository Execute
git config --bool core.bare false git reset --hard
All files should be visible now
Get Only a Specific Branch From the Repo
git clone -b 00_01 https://github.com/planetoftheweb/responsive.git
If you are using a Start branch as a template the logs will still show all the branches up to the last. To clear the log so you can start fresh, you would have to delete the .git folder
rm -drf .git git init git add . git commit -m "first Commit"