- Set global git configuration (user name and email)
git config --global user.name "Jeff Weiss"git config --global user.email jmw182@pitt.edu
- Make folder
mkdir rnel-git-tutorialcd rnel-git-tutorial - Init a local git repo
git init - Show status
git status - Create a .py file
code helloworld.pyprint("Hello, World!")\n - Show status (untracked)
git status - Add, status, and Commit (enter message in editor)
git add helloworld.pygit statusgit commitgit status
- Edit file (make function)
def hello_world(): git status(modified)git diffgit add .git status- Edit again
print("Hello, Nerds!") git status(modified staged and unstaged)git diff --staged,git diffgit commit -m "Make function"git statusgit diffgit restore helloworld.py(removes nerds line)git status
git loggit checkout <SHA>Checkout first commit and show filegit checkout mainand show file
- Checkout new branch
git checkout -b dev - Create/commit new file
code helloeverybody.pyprint("Hello, Everybody!")git add .git commit -m "add helloeverybody.py" git checkout main(new file is deleted)git merge devMerge branch into main (file reappears)git checkout devCheckout dev branch again- Edit file (change Hello->Howdy) and commit
git checkout main- Edit file (hello->hey) and commit
git checkout devgit merge mainAttempt to merge main into branch -> conflict (howdy/hey)- Show how to resolve conflict
- Create empty repo
rnel-git-tutorialon github https://github.com/organizations/pitt-rnel/repositories/new - Configure remote
git remote add origin https://github.com/pitt-rnel/rnel-git-tutorial.git - Push to github
git push -u origin main - Create README on github
git pull
- Create repo
rnel-git-tutorial2on github initialized with readme - Clone repo
git clone https://github.com/pitt-rnel/rnel-git-tutorial2.git - Create branch
git checkout -b dev-ignore - Create
.gitignorefile: http://gitignore.io, add*.ignoretxt - Create
test.ignoretxtfile, show that it is not included in status unless commenting out ignore line - Commit and push .gitignore
- Create PR on github
Demo git blame view in VS Code and/or on GitHub