12. GitHub and VSCodeο
The info below is for the simplest approach where there is only the main branch locally which is being maintained and pushed to the github repository.
For github advice see: `<https://docs.github.com/en/get-started/importing-your-projects-to-github/importing-source-code-to-github/adding-locally-hosted-code-to-github
12.1. GitHub accountο
Create a fee account at github if you donβt already have one.
12.2. VSCode starting from creating a new empty repositoryο
Sign in at github
Create new repo at github: https://github.com/ or at https://github.com/mygithubname?tab=repositories.
Name the new repo the same name as the project folder stored locally on your computer.
Do not create a readme file at this time.
Do not select a license at this time.
Adding a read me or selecting a license will cause an initial commit and will not show the code to use to create the git on your local machine.
Copy the βcreate a new repository on the command lineβ code for use later.
echo "# myrepo" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/mygithubname/myrepo.git
git push -u origin main
12.3. GitHub settingsο
Set Repository default branch to
main(mainis preferred branch name post 2020).
12.4. Initialize GitHub in VSCodeο
In VSCode, initialize git locally by following the steps:
Manually, step by step:
Click on the
source control iconon the left sidebar.Click
initialise git repository.Type in
"initial commit"as the message.Click the
tick iconto commit changes.
Alternatively, hook up remote branch in the VSCode terminal. Run from within the main VScode folder that the docs folder is within.
echo "<# myrepo>" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/mygithubname/myrepo.git
git push -u origin main
Note
README.rst can be used instead of README.md since GitHub also interprets .rst files.
12.5. Initialize GitHub in VSCode starting from an existing repositoryο
In VSCode, run from within the main VScode folder that the docs folder is within.
git remote add origin https://github.com/mygithubname/myrepo.git
git branch -M main
git push -u origin main
12.6. VSCode GitHub updatesο
Click on the
source control iconon the left sidebarType in
"doc update"or specific details as the message in the Source Control section.Click the
tick iconto commit changesThe Source Control Repositories section has icons and dropdowns for key commands.
To push the changes to GitHub, click the icon between the branch icon and tick icon that shows the Push message when hovering over it.
12.7. VSCode GitHub controlsο
Press ctrl + shift + P to open the Command Palette.
Start typing βGitβ to see the various commands.
See more: https://docs.microsoft.com/en-us/learn/modules/introduction-to-github-visual-studio-code/
Recommended youtube: https://www.youtube.com/watch?v=3Tn58KQvWtU&list=PLpPVLI0A0OkLBWbcctmGxxF6VHWSQw1hi
https://www.youtube.com/watch?v=ghL-KlAhBnc uses the command palette in VSCode more.
12.8. VSCode Git staging and commitsο
Click on the
source control iconon the left sidebarAny changes to files or new files will be listed under Changes.
Ustands for untracked (new files not yet added to staging area).Mstands for modified.Dstands for delete (which can result from a name change to a file).
12.8.1. Changes and Staged Changesο
Click a file to see the
git diffvisualization in split columns, showing changes since the last commit.Click the clipboard icon to open the file in VSCode
Click the left loop arrow icon to discard changes to the file since the last commit.
Click the plus icon to add the file to the stage area. It will be listed under Staged Changes.
12.8.2. Commitsο
Type in specific details as the message in the Source Control section.
Click the
tick iconto commit changesIf there are no staged files (Only Changes is shown), then all files are staged and committed.
If there are some files that have been staged (Staged Changes is shown), then only the staged files will be committed.
12.9. VSCode starting from Cloning a repositoryο
For steps involved in starting by cloning a repository see: https://www.youtube.com/watch?v=sz2EM-gkEs0&list=PLpPVLI0A0OkLBWbcctmGxxF6VHWSQw1hi&index=2
If the repository is not a restructuredtext project with .rst files,
sphinx-quickstartmay need to be run once the repo is cloned to the local machine.
To download (clone) a repository from GitHub to your local folder, you can use the following steps:
Navigate to your desired local folder:
cd /path/to/your/folder
Clone the repository. Replace github_username with the username. Replace github_repository with the repository name.
git clone https://github.com/github_username/github_repository.git
This will create a new folder named github_repository in your current directory with all the files from the repository.
12.10. Connecting a Local Git repository Folder to a New GitHub Repositoryο
# Remove the link to the existing Git repository (if any):
git remote remove origin
# Link to the new GitHub repository:
git remote add origin https://github.com/github_username/github_repository.git
# Push your changes to the new repository:
git push -u origin main
12.11. Update to changed repository name in Githubο
git remote set-url origin https://github.com/new-username/new-repository-name.gitgit remote -v