Skip to content

Latest commit

 

History

History
156 lines (123 loc) · 7.33 KB

git_and_github.md

File metadata and controls

156 lines (123 loc) · 7.33 KB

GIT and GitHub

Setup system to use SSH

Create Machine User for Automation

setup, username, & password

  • initial setup
    • git config --global user.name "T. Brian Jones"
    • git config --global user.email "[email protected]"
  • cache username and password so you don't have to type it all the time
    • git config --global credential.helper "cache --timeout=21600"
    • timeout is in seconds
    • this must be done on each machine that you use

migrating from SVN

Migrate without History

  • svn export /project/working/dir/ /exported/project/dir/
  • this will remove all SVN stuff from the project and put clean folders into /exported/project/dir/
  • then just start a new git repo in that folder, or move these files to a git project
  • you lose all project history from svn
    • we generally don't care with our old projects

using git with github

cloning

this is done to checkout a repository the first time, from a remote location ( github ) to a local system ( the computer you are doing dev on )

pushing

push updates on a local machine to github ( the remote git server )

  • simple ( usually works fine ): git push
  • explicit ( eg. when repsoitory contains branches ):

pulling

used to update a local repository with changes that exist in a remote repository ( on github )

  • simple ( usually works fine ): git pull
  • explicit ( eg. when repsoitory contains branches ):

tagging

tags are labels applied to repository versions for later references

  • view local tags ( git tag )
  • add a local tag ( git tag -a tag_name -m "message about this tag"
  • push local tags to remote repository ( git push --tags )
    • creating tags locally only adds them to the local repository. You have to explicitly push tags to github to add them to the master branch.

branching

Branching creates a branched repository that can later be merged with other branches. It's kept "inside" the same repository.

Clone A Specific Branch

  • git clone -b <branch> <remote_repo>

forking

Forking creates a seperate repository which is linked to the parent repository so it's easy to pull updates to the parent into the fork.

Working With Old Revs

  • get a file/folder from an old rev back into the current working branch
    • `git checkout sha-of-old-rev path/to/folder/or/file
    • Example Directory Restoration: git checkout b94110b429c14b9eac40cd38d872cc79beca32c0 utilities/linkedin_position_extractor/

Submodules

allows you to have git repos inside other git repos ( eg. api clients inside a project )

terminology

  • superproject: the master repo with the embedded submodules ( embedded repos )
    • the superproject tracks the version of the submodule and will clone that version into itself when cloned as opposed to the most current version
  • submodule: the repo that is embedded in the superproject

working with submodules

  • clone a repo into another repo: git submodule add https://github.com/Industrial-Interface/cortex_php_api_client.git cortex_php_api_client
  • clone a repo that contains submodules: git clone --recursive https://github.com/Industrial-Interface/cortex_company_crawler.git
  • work on each submodule ( repo ) as you would normally.
  • work on the superproject as you would normally
    • when changes are made to a submodule, however, you will see changes that need to be commited in the submodule repo. Simply commit these as normal.

Helpful Articles

Reverting Revs

revert to an earlier rev and then commit that rev as head

Restoring a Cloned Repo to GitHub

  • Use Case: a repo was cloned. The repo was then deleted from GitHub. You want to restore that repo to GitHub maintianing it's hiustory and otherwise in it's original condition.
    • This is used by TBJ to archive old repos. He clones them, then zips them, then stashes them somewhere, then deletes them from Github.

Method

Problems

Update to Master

  • You want to get all files as they exist in the most recent rev of the master
  • git fetch --all
  • git reset --hard origin/master

HEAD detached from 1c15ff1

  • This means you are not currently attached to a branch
  • git checkout master
  • If you have local changes, you will have to rectify them first.