From HackerspaceWiki
Jump to: navigation, search

Steps For Setting up a GitHub repository via Command Line[edit]

Creating and configuring a repository[edit]

  • Create directory with source code files in it
  • Navigate to the directory using cd
  • Use git init to create a new repository in that directory
  • Use git status to show the status of the files in that directory (should show a list of untracked files)
  • Use git add . to add all files in the directory to first commit to the repository
  • Use git status to check status of files (should show new file: for all files in directory)
  • Use git commit to commit initial versions of files to master branch of repository
  • Use git config --global 'Your Name' to add your username to repository
  • Use git config --global to add your email to repository

Creating a new branch in the repository[edit]

  • Make edits to code base
    • Alt: copy other versions of files into the project directory (use cp [new file path] [project file path])
    • Once you realize the codebase has changed significantly enough from to constitute a new branch, do the following:
  • Use git branch [branchName] to create new branch
  • Use git checkout [branchName] to switch to the new branch
    • ALT PREFERRED: Use git checkout - b [branchName] to create the branch and check it out at the sme time
  • Optional: run git status to check status of branch (should show modified: flags next to files that have been edited)
  • Use git add . to add all directories to be committed, then git commit to commit them to new branch
    • Alt: use git commit add *.js to add all javascript files (or another regex string to specify certain files)
    • PREFERRED ALT: use git commit -am "[message]" to commit add all files and commit them with a message at the same time
  • Optional: use git diff master to display differences between new branch and master
  • Optional: use git log to show commit history of the current branch

Merging branches[edit]

Useful for merging changes from branches back to the master

  • Checkout the branch you want to be the destination of the merge
  • Use git merge [mergeSource] to merge from a source branch to the current branch
  • Optional: if conflicts are flagged, open the file, edit to resolve conflicts, remove branch flags, save, then re-commit from destination branch

Adding an origin and pushing/pulling[edit]

Useful for pushing repositories to GitHub

  • Create a github account
  • Create a remote repository matching s
  • Use git remote add origin [github url] to add origin
  • Use git push origin master to push local repo to remote repo (Note: this is generalizable to git push [repo] [branch]
  • Use 'git pull origin [branch] to fetch and merge remote repo to local repo
    • Alt: git fetch origin [branch] then git merge origin/[branch]

FOR NEXT TIME: pulling from remote repo to live server to replace FTP[edit]

  • Push from localhost to remote origin
  • Pull from remote origin to hosting server (via ssh)
    • For this to work: need RSA key on hosting server
  • Further research google "using local RSA key on remote server" (or look it up on GitHub)