Mtn. Dog Media

How to Use GitHub for WordPress

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 users

Git has 3 Main States

  1. Committed-data is safely stored in your local database
  2. Modified- changed data but not committed yet
  3. Staged-marked a modified file in its current version to go into your next commit snapshot.

Git has 3 Main Sections

  1. Git directory-  where Git stores the metadata and object database for your project (what is copied when you clone a repository from another computer)
  2. 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.
  3. The staging area is a file, generally contained in your Git directory, that stores information about what will go into your next commit

 

git main sections

 

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

  1. Go to GitHub create a free account www.github.com
  2. In the command line of your terminal type: sudo apt-get install git
  3. Inside project base folder use this command:
    1. git init -only do once per project, will track changes
  4. 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 “you@example.com”
  5. In same directory create a file called .gitignore and paste the following inside this file and save: *.pyc
    __pycache__
    myvenv -- change to your virtualenv name
    db.sqlite3 --change to database you are using
    /static
    .DS_Store
  6. Type git status before you do anything to see information about any untracked/modified/staged files, branch status.
  7. Type git add -A .
  8. Type git commit -m "Project name app, first commit"
  9. Go to github sign in and create new repository.
  10. 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.
  11. 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.)
  12. In your terminal type git remote add origin https://github.com/github-username/name-of-repository.git
  13. Then type git push -u origin master prompt to enter username and password
  14. Your code should now be on visible on Github, check to make sure you see it.
  15. 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.
  16. To add untracked changes type git add name-of-file-path
  17. 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.
  18. If making changes on github, edit and add as needed commit to master branch and in command line type git pull origin master