How-To-GitHub-Basically
(Assumes Using Windows 11
and
Visual Studio Code)
Powershell
Windows Subsystem for Linux
IDE (Integrated Development Environment) (Visual Studio Code)
git bash
GitHub
Goes through simple setup for version control system
Goes through some simple git commands
Refers to some commands which can delete so to be used with caution
towards the end of this document.
Use at your own risk.
Provide dedicated beginner with a somewhat beginner friendly reference to some
common commands and a few issues / workarounds / fixes possibly encountered along the way.
Not suitable for any production or important work just for learning purposes.
Warning: some commands (especially towards the end of document) may not be suitable for all projects, so be very careful!
Intended for very informal reference purposes only and to possibly avoid having to dig through
the much more extensive, offical git-scm.com documentation, for example.
This is very much not an official reference in any sense.
Errors and omissions accepted.
-
Download Powershell using commands given:
winget search Microsoft.PowerShell
-
Add the full absolute path to the folder where
Powershell.exe
is located toWindows System Environment Variables > Path
by clickingNew
-
Copy command
wsl --install
-
Open Powershell
-
Paste Command
wsl --install
into Powershell -
Install git bash
-
Add git bash install folder for git bash to System Environment Variables on Windows
-
Install IDE (e.g. VSCode)
-
Add VSCode folder to System Environment Variables
-
Sign up for GitHub Account
-
Create new Repository
-
Click Dropdown arrow beside Clone Button
-
Copy Repository url from Clone dropdown
-
Open IDE (e.g. VSCode)
-
Open integrated terminal
-
If (base) shows (due to Anaconda installed) type
deactivate
-
Click cog wheel in bottom left corner for settings
-
Sync Visual Studio Code with GitHub
-
(May need to Install some Recommended Extensions) (go to left vertical column and click on symbol of blocks about 5th from the top)
-
In Integrated Terminal: type:
git clone
and then space and Paste url content Copied from GitHub Clone Button into integrated terminal in Visual Studio Code -
Press Enter (this will clone repo)
-
Click File > Add New File > name it README.md (if not already in repository)
-
In terminal: Type the following 3 git commands pressing enter after each
-
git add .
-
git commit -m "Add README md file"
-
git push
-
git status
-
git pull
Optional commands (for later reference) for cloning another repository into local and then pushing to own repository:
-
To clone another repository:
-
Clone the repo from [other repository to be cloned] to your local machine as follows:
-
Click dropdown arrow beside green clone button on repository to be cloned, and copy <url ending in .git>
-
Create a new repo at github.
-
To Setup own remote repository: Go to GitHub.com > Login > Click New Repository > (in this case: do not make any edits on opening screen (apart from name and setting public or private) to get to screen with "If you've done this kind of thing before, then copy url .git)
-
VSCode > File > New Window
-
Set up local folder
-
In VSCode: Go to left vertical column, click third image from top to go to git commands GUI (Graphic User Interface) (can either use this or the equivalent terminal commands git clone <paste repo url with .git ending from Clone buitton drropdown menu on GitHub> interchangeably)
-
if using GUI Click Clone, paste url copied from GitHub Repository to be cloned into the window that appears, click Enter to clone into currently selected local folder.
git remote rm origin
StackOverflow | How to remove origin from git repository
-
$ git remote set-url origin https://github.com/YOU/YOUR_REPO
StackOverflow -
git remote -v
to check if there is one line ending in (fetch) and one ending in (push) (2 lines total). If there are 4 lines, then can remove the lines not beginning with origin. -
If get error this site contains instructions to fix and is also a reference for commands mentioned here. How to fix ‘fatal: remote origin already exists’ Git error
-
Reference for following commands: Git push existing repo to a new and different remote repo server?
-
git remote rename origin upstream
-
git remote add origin URL_TO_GITHUB_REPO
-
git push origin master
-
git checkout <commit>
full command: with optional flags: git checkout [-q] [-f] [-m] [--detach] -
Partial command:
git merge
Reference: git merge | git-scm.com
Side note:
from git merge reference above:
Can use the following commands with CAUTION if read up a bit on them first here and possibly elsewhere in certain situations:
--ff
--no-ff
--ff-only
Specifies how a merge is handled when the merged-in history is already a descendant of the current history. --ff is the default unless merging an annotated (and possibly signed) tag that is not stored in its natural place in the refs/tags/ hierarchy, in which case --no-ff is assumed.
With --ff, when possible resolve the merge as a fast-forward (only update the branch pointer to match the merged branch; do not create a merge commit). When not possible (when the merged-in history is not a descendant of the current history), create a merge commit.
With --no-ff, create a merge commit in all cases, even when the merge could instead be resolved as a fast-forward.
With --ff-only, resolve the merge as a fast-forward when possible. When not possible, refuse to merge and exit with a non-zero status.
-
Partial command:
git branch
Reference: git branch | git-scm.com -
git reset --soft HEAD
orgit reset --soft <commit to revert to>
(Note: soft means not permanent, and can undo if wrong, however, next command uses hard, which cannot be undone, so proceed with Caution!) -
WARNING!!, be very careful with this one, as it DELETES!! things:
git reset --hard
to undo last commit, OR: To go back multiple commits!:git reset --hard <commit-hash>
Be aware that the git reset –hard HEAD or git reset –hard HEAD@{n} command would remove your uncommitted changes, even if you staged them. If you don’t want your unstaged changes to be removed, you can use the --soft flag instead of the --hard flag. | Git Reset Hard – How to Reset to Head in Git | freeCodeCamp
Update 18-01-2024:
The following may be needed to make WSL, VSCode, git and GitHub work together effectively:
Install the GitHub Pull Requests and Issues extension in VSCode
In addition to point 4. above,
(namely PowerShell wsl --install
)
Also, if this error happens:
WSL broken with "Class not registered" code 4294967295 (0xffffffff) #8268
To fix "Class not registered" error, I only repair WSL on "Settings > Applications > Instaled Applications > Windows Subsystem for Linux > Advanced Options > Repair". After do that, my WSL command returned to work.
To fix "Class not registered" error, I only repair WSL on "Settings > Applications > Instaled Applications > Windows Subsystem for Linux > Advanced Options > Repair". After do that, my WSL command returned to work.
I ended up having to uninstall Windows Subsystem for Linux from here, disable the windows feature (start menu > Turn windows features on or off), reboot, then re-enable it
Summary:
In addition to toggling on and off wsl in turn Windows Features on or off in Control Panel:
-
Windows PowerShell 2.0
-
open PowerShell (may need to run as Admin)
-
wsl --install
-
reboot
Other references for this:
WSL broken with "Class not registered" code 4294967295 (0xffffffff) #8268
How to deal with the problem: “Error code: Wsl/CallMsi/REGDB_E_CLASSNOTREG”
Error code: Wsl/CallMsi/REGDB_E_CLASSNOTREG #10882
How can I fix WSL.exe sudden corruption in unknown DLL giving error 0x80040154 on Win11
Update 23-03-2024:
git remote set-url origin <git url here>
gives:
error: No such remote 'origin'
Reason:
here:
basically:
1 - You never told Git to start tracking any file
For that you need to stage the files of interest, using:
git add .
git commit -m "some descriptive message"
2 - You haven't set up the remote repository
Summary of Solution:
git remote add origin <GitHub Repository url goes here>
Source: StackOverflow:
Why does Git tell me "No such remote 'origin'" when I try to push to origin? | StackOverflow
after above fix
can check it worked with:
git remote -v
This should show that the
<GitHub Repository url>
pasted in the above is listed as
(origin)
for both:
(fetch)
and
(push)
Update 20-07-2024:
Search and Reference on LF replacement by CRLF in git
How can I stop this error. LF will be replaced by CRLF the next time Git touches it