Git & GitHub
git init
initializes a local git directoryrm -fr .git
removes a local git directorygit status
status of staging areagit log
show log of changesgit diff filename.txt
see recent changes made to code
Navigate
git branch
lists all branchesgit branch branchName
creates a new branchgit checkout branchName
move into branchgit checkout -b branchName
creates a new branch and moves into it
Commit
git add <filename>
add file to staging areagit add .
add all files that aren’t currently stagedgit reset
removes 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-edit
amend a commit without changing the commit message
How to write a good commit message (opens in a new tab)
Local branches
git checkout main
thengit branch -D <branchname>
delete local branch
Remote branches
Origins
git remote add origin <repository-url>
add remote origingit remote remove origin
remove remote origingit remote set-url origin url
update remote origingit remote -v
view connected remote repositories
Pull and push
git pull origin main
pull remote main branch into branchgit push origin main
push your branch to the remote repository main branchgit push origin branchName
push your branch to the remote repositorygit checkout -b new-branch origin/branchname
checkout remote branch, good for testing PRs
Problems / Solutions
Wont push to a remote repo that has a README
git fetch --all
git rebase origin/main