Github#
Install Git, Github, and connect your local computer to remote repos.
Create a new repository on GitHub#
Go to GitHub and log in to your account.
Click on the ‘+’ icon in the upper right corner and select ‘New repository’.
Name your repository, add a description (optional), and choose to make the repository either public or private.
You can initialize the repository with a README, .gitignore, or license if you want.
Click ‘Create repository’.
Connect the repository to a local directory#
Open the terminal on your computer.
Use the’ cd’ command to navigate to the directory where you want to clone the repository. For example, if you want to clone the repository to a directory named ‘my_directory’ on your C drive, you would use the command
cd C:/my_directory
. You can also navigate to the file location, right-click in a blank space, and select ‘open in terminal’. Make sure to activate the correct environment for the project.Clone the repository by running the command
git clone https://github.com/username/repository.git
, replacing ‘username’ with your GitHub username and ‘repository’ with the name of your repository. This will create a new directory in ‘my_directory’ with the same name as your repository, and this new directory will be linked to the repository on GitHub.Navigate into the new directory with the command
cd repository
, replacing ‘repository’ with the name of your repository.
Push changes to GitHub#
Make any changes you want in the new directory.
Once done, you can add these changes to the staging area with the command
git add .
.Commit the changes with the command
git commit -m "Your commit message"
, replacing ‘Your commit message’ with a brief description of your changes.Push the changes to GitHub with the command
git push origin master
. Please note that you need to have Git installed on your computer to use the git command. If you don’t have Git installed, you can download it from the Git website.
Clone an existing repo#
Find the repository on GitHub
Go to GitHub and log in to your account.
Navigate to the repository you want to clone.
Copy the github URL
In the repo, click the ‘green
<> Code
button near the top of the repository’s page.In the dropdown that appears, click copy the repository’s URL to your clipboard.
Open the terminal on your computer.
In a terminal, navigate to the directory where you want to clone the repository using the
cd
command. For example, if you want to clone the repository to a directory named ‘my_directory’ on your C drive, you would use the commandcd C:/my_directory
.An easier way to the correct directory is to open the directory in your file explorer, right-click on a space in the directory, and select open in terminal.
Clone the repository by running the command
git clone https://github.com/username/repository.git
, replacing ‘username/repository.git’ with the URL you copied in step 1. This will create a new directory in ‘my_directory’ with the same name as your repository, and this new directory will be linked to the repository on GitHub.
Clone a repo in VS Code#
Open VS Code
Open the command palette by typing
Ctrl+Shift+P
Type
Git: Clone
and select it from the dropdown listPaste the repo URL you want to clone and click enter
Choose the directory where you want to store the repo on your computer
Click
Open
to open the repo in a new window orAdd to Workspace
to add it to the workspace you are working in.
Git init#
You need to initialize Git in each new project you want to control version. You do this by navigating to your project’s directory in the terminal and running the command git init. This creates a new Git repository in the current directory.
For example, if you have a project in a directory named ‘my_project’ on your C drive, you would initialize Git in this project with the following commands:
cd C:/my_project
git init
After running these commands, you’ll see the message “Initialized empty Git repository in C:/my_project/.git/”. This means that Git has been initialized in the ‘my_project’ directory, and you can now use Git commands to track changes to your project.
Push changes in VS Code#
To save your local changes in VS Code and ‘push’ them to your remote repo, follow these steps:
Edit your files and save the changes.
Click on the Source Control icon in the Activity Bar on the side or press
Ctrl + Shift + G
to open the Source Control panel.Click the ‘+’ icon next to each file you want to stage, or click the ‘+’ icon at the top to stage all changes.
In the text box at the top of the Source Control panel, enter a commit message and press
Ctrl + Enter
to commit the changes.Click on the ‘…’ icon at the top of the Source Control panel and select ‘Push’ from the dropdown menu.
Select sync from the blue button.
Push changes using Git#
Or you can push changes in the terminal using Git:
Make sure you’re in the correct repo and env in your terminal. Use the
cd
command to change directories, e.g.,cd C:\my_project
Stage changes using the command
git add .
to stage all the repo changes.Commit changes using the command `git commit -m ‘your commmit message’. Make sure to change the commit message in quotes to reflect what changes you made.
Push the changes using `git push origin master, ‘ sending them to the master branch of the remote repo.
This will look like the following, where you enter each line and hit enter separately:
cd C:/my_project
git add .
git commit -m "Your commit message"
git push origin master