Skip to content

CoderSales/How-To-GitHub-Basically

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 

Repository files navigation

How-To-GitHub-Basically

Description

How-To-GitHub-Basically

(Assumes Using Windows 11

and

Visual Studio Code)

Content

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.

Purpose

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.

Steps

  1. Go to Windows website to get Powershell

  2. Download Powershell using commands given: winget search Microsoft.PowerShell

  3. Add the full absolute path to the folder where Powershell.exe is located to Windows System Environment Variables > Path by clicking New

  4. Click here to go to Windows Subsystem for Linux

  5. Copy command wsl --install

  6. Open Powershell

  7. Paste Command wsl --install into Powershell

  8. Download git bash

  9. Install git bash

  10. Add git bash install folder for git bash to System Environment Variables on Windows

  11. Download an IDE like Visual Studio Code

  12. Install IDE (e.g. VSCode)

  13. Add VSCode folder to System Environment Variables

  14. Go to GitHub

  15. Sign up for GitHub Account

  16. Create new Repository

  17. Click Dropdown arrow beside Clone Button

  18. Copy Repository url from Clone dropdown

  19. Open IDE (e.g. VSCode)

  20. Open integrated terminal

  21. If (base) shows (due to Anaconda installed) type deactivate

  22. Click cog wheel in bottom left corner for settings

  23. Sync Visual Studio Code with GitHub

  24. (May need to Install some Recommended Extensions) (go to left vertical column and click on symbol of blocks about 5th from the top)

  25. 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

  26. Press Enter (this will clone repo)

  27. Click File > Add New File > name it README.md (if not already in repository)

  28. In terminal: Type the following 3 git commands pressing enter after each

  29. git add .

  30. git commit -m "Add README md file"

  31. git push

  32. git status

  33. git pull

Optional commands (for later reference) for cloning another repository into local and then pushing to own repository:

  1. To clone another repository:

  2. Clone the repo from [other repository to be cloned] to your local machine as follows:

  3. Click dropdown arrow beside green clone button on repository to be cloned, and copy <url ending in .git>

  4. Create a new repo at github.

  5. 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)

  6. VSCode > File > New Window

  7. Set up local folder

  8. 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)

  9. 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.

Disconnect from cloned repo remote repository:

  1. git remote rm origin StackOverflow | How to remove origin from git repository

Connect to own new repository remote repository on GitHub:

  1. $ git remote set-url origin https://github.com/YOU/YOUR_REPO StackOverflow

  2. 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.

  3. 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

Miscellaneous commands possibly needed:

  1. Reference for following commands: Git push existing repo to a new and different remote repo server?

  2. git remote rename origin upstream

  3. git remote add origin URL_TO_GITHUB_REPO

  4. git push origin master

Further miscellaneous commands:

  1. git checkout <commit> full command: with optional flags: git checkout [-q] [-f] [-m] [--detach]

  2. 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.
  1. Partial command: git branch Reference: git branch | git-scm.com

  2. git reset --soft HEAD or git 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!)

  3. 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:

Search: PS C:\WINDOWS\system32> wsl --install Class not registered Error code: Wsl/CallMsi/REGDB_E_CLASSNOTREG

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

Git failed error warning: in the working copy of LF will be replaced by CRLF the next time Git touches it LF will be replaced by CRLF the next time LF will be replaced by CRLF the next time Git touches it warning: in the working copy of LF will be replaced by CRLF the next time Git touches it warning: in the working copy of LF will be replaced by CRLF the next time Git touches it warning: in the working copy of LF will be replaced by CRLF the next time Git touches it warning: in the working copy of LF will be replaced by CRLF the next time Git touches it warning: in the working copy of

How can I stop this error. LF will be replaced by CRLF the next time Git touches it


References

freeCodeCamp

git-scm.com

stackoverflow

learn.microsoft.com

Visual Studio Code