Skip to content

Latest commit

 

History

History
82 lines (78 loc) · 4.04 KB

File metadata and controls

82 lines (78 loc) · 4.04 KB

Getting Started with git

Basics

Local Repository

  • Open terminal in MacOS or <> in Windows to access command line
  • Create a directory
    • Windows
    • MacOS
      • $ cd to a folder, e.g. "~/Documents"
      • $ mkdir <directory_name>
      • $ cd <directory_name>
    • Initialize local repository: git init
    • Set global config options:
      • $ git config --global user.name <user name>"
      • $ git config --global user.email <user email>"
  • Create a file
    • Use command line or graphical environment to create a new text file called <unity_id>.txt.
    • Edit the file using the text editor of your choice and add some text to your file.
  • From the command line
    • $ git status
      • Note: "untracked files"
    • $ git add <unity_id>.txt
      • Note: this is staging a file. You must do this before commiting the file to your repo.
    • $ git status
      • Note: "No commits yet" and list of changes to be commited.
    • $ git diff
  • Edit <unity_id>.txt and save
  • From command line
    • $ git diff
      • Note: now we can see changes to file.
    • $ git reset <unity_id>.txt
      • Note: this unstages a file.
    • $ git status
      • Note: again we have untracked files.
  • Create another file called <unity_id>_2.txt and add some text to the file.
  • From command line
    • $ git add .
      • Note: this stages all unstaged files in the current directory.
    • $ git status
      • Note: both files should be listed now.
    • $ git commit -m "First commit."
    • $ git status
    • $ git log
      • Note: our first commit is listed here.

Remote Repository

  • Log into your github account (you can use your NCState account or a personal one)
  • Create a new repository named "git_Workshop"
    • Make sure "Initialize this repository with a README" is unchecked
      • Having existing files in your remote repository will produce an error "refusing to merge unrelated histories"
      • If you forget, you can search for this error in your browser which should provide you with steps to get your local and remote repositories "in sync".
  • Copy git remote add origin code to your clipboard
  • Making sure you are in the directory where your local repo resides, paste command into your command line. There are two commands that get copies:
    • $ git remote add origin <url to remote>
      • Note: this command links your local and remote repos together.
    • $ git push -u origin main
      • Note: this command pushes the files which have been commited in your local repository to your remote repository.
  • From command line
    • $ git status
      • Note: take a moment to compare this output to output generated before linking your local and remote repos.
    • $ git log
      • Note: take a moment to compare this output to output generated before linking your local and remote repos.
  • In remote repo
    • Note files which have been added (from local repo)
    • Create a file in the remote repository
  • In local repo
    • Edit a file in your local repo (either text file you created)
  • From command line
    • $ git commit -a
      • Note: the -a parameter adds all unstaged files without using a separate git add. If we leave off the -m and commit message causes git to open your default editor. You can use git config --global core.editor to change the default editor. See Pro git for additional information.
    • $ git push
      • Note: NOOOOO!!!! Scary error! Whyyyy?!?! No worries! This error is a result of having made changes to your remote repo which haven't yet been incorporated into the local. We just need to grab those then we can continue happily.
    • $ git pull
      • Note: this grabs the changes from the remote repo into your local repo.
    • $ git push origin main
      • Note: this will push your local changes to your remote repo.
    • $ git log
      • Note: take note of the order of commits now. Interactions with the remote repo show up now too.

Reference

Pro git