What is GIT?
- Distributed Version Control System
- Local and Remote
Local : Git tracking on your computer
Remote: Github, GitLab, BitBucket, etc.
Installing GIT locally
- git — version
- Configure name/email
git config — global user.name (FirstName LastName)
git config — global user.email (Your email)
git config — global color.ui auto
Initializing a Repo
(Repo: folder you want to have git track)
- change directories in your terminal to the folder you want to track
cd project-folder-name - or create a new folder : mkdir (folder name)
create a new file : touch (file name) (ex: touch README.md) - Then initialize the repo
git init - If you need to remove git tracking, running rm -rf.git
Be careful with the rm terminal command as it will permanently delete files/folders specified — you will not find them in the trash.
Staging area and committing
- add files/folders to the STAGING area
git add README.md
git add folder-name/
git add -A OR git add .
git reset README.md (removes README from staging area) - Commit changes in STAGING area
git commit -m “add like button to profile photos”
If you don’t include the -m and message, you will enter Vim (or your default text editor) which we will not cover here today
Branches
git branch
git branch new-feature
git checkout new-feature
- Delete the branch
git branch -d new-feature
git branch -D new-feature
Pulling/Pushing to Remote
git pull origin main
- git pull (remote) (branch)
- This accomplishes both a fetch and a merge
git push origin main
- git push (remote) (branch)
Other helpful Remote Commands
git clone (url)
- clone a remote repo locally
git remote add (variable) (link)
- add a remote
git remote rm (variable)
- remove a remote
git remote -v
- shows path info to remote repos
git branch -a
- shows list of local and remote branches
Merging
you don’t use them if you use Github. If you want to merge locally you can use below commands.
git checkout main -> switch working branch to main
git pull origin main -> pull updated code
git branch — merged -> tells which branches have been merged
git merge (name of branch)
git push origin main
Helpful commands
git help git -> overview of git in general
git help (command) (git help commit)
git (command) — help (git commit — help)
git status — shows changed files yet to be committed or staged
git log — log of all commits incl. id/message/user/date
git diff — see changes not yet in staging area
git branch — lists all branches and highlights one currently on