Git Flashcards
git init
initializes git repository -> creates a special folder to hold all of your snapshots (commits) of code
command to show all files, including hidden ones
ls -la
git add
adds files to staging area so that we can later take a snapshot of all these changes and save to the repository
example:
git add index.html -> adds that file to staging area
git add *.html -> adds any file that ends in .html
git add .
every file within folder gets added to the staging area
git status
shows you everything in staging area (waiting to be saved in to snapshot)
git commit
git commit -m “text”
commits all the files in staging area -> saves them to original repository that was created
-m lets you add special message,
if you DONT use -m you will go in to a text editor with the assumption you want to create a longer commit
if youre in VIM: type i (allows you to insert); after typing commit; to leave escape -> type :wq -> enter
git remove …..
possible to remove things from staging area (didnt get full command)
git branch -M main
changes name of staging area to main (instead of master) -> based on movement to move away from “master” hierarchy
What should you do if you want to make some majorrr changes to your code that would likely mess everything up?
create a new branch. you can use git status to see what you’re currently on.
git branch / git branch “risky”
git checkout / git checkout “risky”
git status
git branch branchName
git checkout branchName
creates another branch; takes you to the branch
git merge branchName
add changes from another branch to Main
github
using just git saves things locally. but we can save git repositories to the cloud (remote backup) through github
how to push code to the cloud (github)
go to github; there’s a plus sign -> “create new repository”
git remote -> sets up where remote code gets sent to
git push -u origin main… ->
host code….