Version Control
A brief overview of version control, using a version control system called Git.
Version Control
Git is a very important tool used by developers to keep code, files, and almost anything else, in sync between their local development environment (local computer) to a remote server (on the internet, or on a local network server). Git is a type of tool called a Version Control System. Version Control Systems are used to keep track of each version, or change, of a file. This allows users to go back to a point in time with their code, or to manage the differences between two different versions of a file if multiple people have worked on it.
We will be covering the following 3 topics of Version Control:
Install Git
Navigate to https://git-scm.com/downloads and download the version of git for your platform. Most of you will download the Windows version. Perform a “push-through” install of Git, accepting all the default options.
Note: If you are on Linux or MacOS, you can install it from the command line.
- sudo dnf install git – RedHat, CentOS, AlmaLinux, and variants
- sudo apt install git – Ubuntu and variants
- brew install git – MacOS (with Homebrew installed)
Link Local Git to GitHub
- Create GitHub Account
- In VS Code Terminal >
- ssh-keygen -t rsa -b 4096 -C your_email@example.com
- Replace email with the email associated with the GitHub Account
- eval "$(ssh-agent -s)"
- ssh-add ~/.ssh/id_rsa
- This should be the path that the passkey was saved to from above
- cat ~/.ssh/id_rsa.pub
- This should be the path that the passkey was saved to from above
- COPY TO CLIPBOARD
- ssh-keygen -t rsa -b 4096 -C your_email@example.com
- In GitHub Account >
- Settings > SSH & GPG Keys > New SSH Key > PASTE FROM CLIPBOARD > Add Title > Add SSH Key
- In VS Code Terminal >
- ssh -T git@github.com
- This will verify the connection with GitHub
- ssh -T git@github.com
Basic Commands in VS Code
Configure Global Settings:
- git config –global user.name “name”
- git config –global user.email “email@email.com”
Create (Make) Directory:
- mkdir nameOfDirectory
Change Directory:
- cd
- cd .. (go up one directory)
Create File:
- PowerShell
- code -r nameOfFile
- SSH
- touch nameOfFile
Create Repository:
- git init
Create Branch:
- git branch nameOfBranch
Switch to Branch:
- git checkout nameOfBranch
- git switch nameOfBranch
Merge Branch to Main/Master:
- git merge nameOfBranch
- Resolving Conflicts:
- Resolve conflict as needed.
- git add FILE.md
- git commit -m "Resolved conflict between nameofBranch and Main/Master..."
Verify Current Branch:
- git status
Stage and Commit Files:
- git add . (or git add nameOfFile)
- git commit -m “commit message goes here”
Review Commit History:
- git log
Link Local Repository to GitHub Repository
- git remote add origin https://github.com/username/name-of-repository.git
- git pull origin main