How to Use GitHub for WordPress
The developers at Mtn Dog Media wanted an easy and efficient way to share their code, work and knowledge both within our own team and also to other developers. We thought this would be beneficial as we find ways to better to accomplish requests from our customers, thus we have created our own Github account!
What is GitHub?
Github is a repository hosting service for Git and provides a web-based graphical interface for git. It can and usually is treated as a social platform to share knowledge and work.
What is GIT?
Git is a version control system that records any changes to a file or set of files. It thinks of its data more like a set of snapshots of a miniature filesystem. Every time you commit, or save the state of your project in Git, it basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot. To be efficient, if files have not changed, Git doesn’t store the file again, just a link to the previous identical file it has already stored.
Why bother Using Git?
Git allows you to:
- Revert or refer to files from an earlier state
- Compare changes to project or files over time
- Keep track of each users modifications
- Users can modify at files at the same time
- All files are in one place so easy to make changes
- Ability to upload changes at anytime
- Files are check-summed to ensure integrity
- Serves as back-up for all files in case site crashes
Git has 3 Main States
- Committed-data is safely stored in your local database
- Modified- changed data but not committed yet
- Staged-marked a modified file in its current version to go into your next commit snapshot.
Git has 3 Main Sections
- Git directory- where Git stores the metadata and object database for your project (what is copied when you clone a repository from another computer)
- Working directory- is a single checkout of one version of the project, these files are pulled out of the compressed database in the Git directory and placed on disk for you to use or modify.
- The staging area is a file, generally contained in your Git directory, that stores information about what will go into your next commit
Useful Git Commands
- git init - use to start tracking a project
- Git status - to see what changes have been tracked, modified or staged
- git add- specify the files you want to track, followed by a commit: git commit -m ‘project version’
18 Steps to Install Git and Use Github
- Go to GitHub create a free account www.github.com
- In the command line of your terminal type: sudo apt-get install git
- Inside project base folder use this command:
- git init -only do once per project, will track changes
- Next type these commands with your username and password you created on github git config --global user.name "Your UserName"
git config --global user.email “firstname.lastname@example.org”
- In same directory create a file called .gitignore and paste the following inside this file and save: *.pyc
myvenv -- change to your virtualenv name
db.sqlite3 --change to database you are using
- Type git status before you do anything to see information about any untracked/modified/staged files, branch status.
- Type git add -A .
- Type git commit -m "Project name app, first commit"
- Go to github sign in and create new repository.
- Name your repository accordingly and leave the "initialise with a README" tickbox un-checked, leave the .gitignore option blank since that has been done manually) and leave the License as None.
- Copy the url under HTTPS and go back to your terminal (need to hook up the Git repository on your computer to the one up on GitHub.)
- In your terminal type git remote add origin https://github.com/github-username/name-of-repository.git
- Then type git push -u origin master prompt to enter username and password
- Your code should now be on visible on Github, check to make sure you see it.
- If you made updates check by typing git status in your terminal. This will show changes waiting to be committed and changes not yet staged as untracked.
- To add untracked changes type git add name-of-file-path
- Once all changes are staged to be committed type git push -u origin master prompt , type in username and password, go to github to see changes added.
- If making changes on github, edit and add as needed commit to master branch and in command line type git pull origin master