Skip to content

Latest commit

 

History

History
54 lines (54 loc) · 2.48 KB

GitTutorial.md

File metadata and controls

54 lines (54 loc) · 2.48 KB

Git Tutorial

Setup (config)

  1. Set global git configuration (user name and email)
    • git config --global user.name "Jeff Weiss"
    • git config --global user.email jmw182@pitt.edu

Local init and first commit

  1. Make folder mkdir rnel-git-tutorial cd rnel-git-tutorial
  2. Init a local git repo git init
  3. Show status git status
  4. Create a .py file code helloworld.py print("Hello, World!")\n
  5. Show status (untracked) git status
  6. Add, status, and Commit (enter message in editor) git add helloworld.py git status git commit git status

Staging area demo

  1. Edit file (make function) def hello_world():
  2. git status (modified)
  3. git diff
  4. git add . git status
  5. Edit again print("Hello, Nerds!")
  6. git status (modified staged and unstaged)
  7. git diff --staged, git diff
  8. git commit -m "Make function" git status git diff
  9. git restore helloworld.py (removes nerds line) git status

Log and history

  1. git log
  2. git checkout <SHA> Checkout first commit and show file
  3. git checkout main and show file

Branching, merging, conflicts

  1. Checkout new branch git checkout -b dev
  2. Create/commit new file code helloeverybody.py print("Hello, Everybody!") git add . git commit -m "add helloeverybody.py"
  3. git checkout main (new file is deleted)
  4. git merge dev Merge branch into main (file reappears)
  5. git checkout dev Checkout dev branch again
  6. Edit file (change Hello->Howdy) and commit
  7. git checkout main
  8. Edit file (hello->hey) and commit
  9. git checkout dev
  10. git merge main Attempt to merge main into branch -> conflict (howdy/hey)
  11. Show how to resolve conflict

Push to Github

  1. Create empty repo rnel-git-tutorial on github https://github.com/organizations/pitt-rnel/repositories/new
  2. Configure remote git remote add origin https://github.com/pitt-rnel/rnel-git-tutorial.git
  3. Push to github git push -u origin main
  4. Create README on github
  5. git pull

Init on Github, gitignore, PR

  1. Create repo rnel-git-tutorial2 on github initialized with readme
  2. Clone repo git clone https://github.com/pitt-rnel/rnel-git-tutorial2.git
  3. Create branch git checkout -b dev-ignore
  4. Create .gitignore file: http://gitignore.io, add *.ignoretxt
  5. Create test.ignoretxt file, show that it is not included in status unless commenting out ignore line
  6. Commit and push .gitignore
  7. Create PR on github

Git blame

Demo git blame view in VS Code and/or on GitHub