Git & GitHub
git initinitializes a local git directoryrm -fr .gitremoves a local git directorygit statusstatus of staging areagit logshow log of changesgit diff filename.txtsee recent changes made to code
Navigate
git branchlists all branchesgit checkout -b branchNamecreates a new branch and moves into itgit checkout branchNamemove into branch
Commit
git add <filename>add file to staging areagit add .add all files that aren’t currently stagedgit resetremoves all files from git status staging areagit commit -m “change message”commits files locallygit commit -m “title” -m “longer description”add a description of changesgit commit --amend -m "change message"amend a commit and change the commit messagegit commit --amend --no-editadd to a commit without changing the commit message
How to write a good commit message
Local branches
git checkout mainthengit branch -D <branchname>delete local branchgit checkout -b clean-branch-name origin/maincreate a clean branch from maingit branch -m old-branch-name new-branch-namerename a branch
Remote branches
Origins
git remote add origin <repository-url>add remote origingit remote remove originremove remote origingit remote set-url origin urlupdate remote origingit remote -vview connected remote repositories
Pull and push
git pull origin mainpull remote main branch into local branchgit push origin branchNamepush branch to the remote repo feature branch orgit push -u origin branchNamepush feature branch to the remote repo and set it as the upstream branch, thengit pushwill push to that branchgit checkout -b new-branch origin/branchnamecheckout remote branch, good for testing PRs
Problems / Solutions
Wont push to a remote repo that has a README
git fetch --all
git rebase origin/mainWont push because file is too large (remote hung up)
Increase file size limit to 1GB
git config http.postBuffer 1048576000Merge conflicts
git pull origin main
git checkout feature-branch
git rebase main
# fix conflict
git add .
git rebase --continue
# repeat until conflicts are resolved
git push origin feature-branch --force