| Git | Github |
|---|---|
| a tool that allows creation of a local repository | allows hosting the central repository on a remote server |
| a version control system | a repository hosting service |
| Command | Description |
|---|---|
| git init | initialise a project for version control (do this from within the folder to be initialised) |
| git status | see where changes have been made, but not yet added |
| git add . | add all outstanding changed files into staging
You can specify a particular file if you don't want to add them all |
| git commit -m "{message}" | commit change to git and add a relevant comment to identy changes made
These will be visible against all affected files in GitHub. |
| git log | log of all commits
Note: you need to enter q (for Quit) to get out of the status window |
| git remote add origin {url} | sets up connection to between repository on your PC and the one in GitHub |
| git push origin {branchname} | sends code to the {branchname} branch on git-hub (usually master, but you have to specify) |
| git remote -v | Shows you the target url of the repository on GitHub if you are connected |
| git clone {url} | takes a copy from github and loads it on your pc
NB puts the code into a new folder |
| rm -rf .git | Trouble shooting - delete local git repository
Very useful if you have cloned to the wrong location and want to remove the error. Remember to move / copy your changed code to a tempoaray location before you remove the local repository as it will be deleted! |
| pwd | print working directory (show me the place in my folder structure that I am right now) |
| cd .. | move up one level in my folder structure |
| cd - | return to the last directory I was in (NB. This is a toggle setting) |
| ls | list structure (equivilent to dir command in DOS) |
| ls -ltr | same as ls, but shows details of file permissions, size, modification time and name, in reverse
order
For a full list of list commands, type ls --help on the command line and test a few out -l : use a long list format -t : sort by modification time, newest first -r : reverse order when sorting |
| mkdir | Make directory (folder) - will give an error if it already exists |
| rmdir | Remove (delete) a directory (NB must be empty)
A directory cannot be removed if it is still registered as a git project. use rm -rf .git to fix |
| rm | delete file(s) from a directory
rm --help gives some assistance e.g. you can delete all jpg files by typing rm *.jpg |