Git and GitHub Tutorial for Beginners¶
Userful Links¶
Turtorial on Youtube.
Get Git¶
https://git-scm.com
-
Hit ‘Downloads’
-
Select your operating system and then run through the installation process
-
With Git Installation, it came with a termianl called Git Bash.
Launch Gitbash: Click on your Start menu and type in Git Bash
windows view:
Once you’ve installed Git, you can use any terminal now to interact with Git. For this lesson, I am going to use Git Bash because it came with the Git installation on Windows. If you want, you could also download third party teminals like Hyper.is, which works across all different paltforms.
Use Git¶
- Git Configuration:
To credit your identity, we need to specify your name and e-mail address:
git config --global user.name "type your name"
and then hit Enter, next set your e-mail address:
git config --global user.email yourEmail@xxxx.com
We need to set the default branch name:
git config --global init.default branch main
Ask for help
git config -h
Check Git-config Manual Page (no internet access required),check the descriptions of commands, the options of the commands, and etc.
git help config
Back to File Explorer , to clear the history and get a fresh view, type clear
To track files on your computer, first, change the current directory to the location of the file:
Back within Git Bash, cd
change directory
Now, to turn this into a Git repository,
type git init
or git initialize
Now, if you click on ‘show hidden files’, you should see a .git
file, which indicates that the file has been converted to a git repository.
Check the status of the repository: git status
To track a specific file , type git add <file>
To confirm a file being tracked, type git status
again;
To unstage(stop tracking) a tracked file, type git rm --cached <file>
Tips:
A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected; An example of ignoring .txt files being tracked: Create a file with the extension ‘.gitignore’ and open it with any text editor, type.txt
and save the file.
Use Git II¶
To track all of the files: git add --all
; git add -A
; git add .
;
.
for the entire directory.
To commit :git commit -m "the message"
To see what’s been modified: git diff
For the original part in red; the changed part is in green.
In Git, there’re 3 different working environments:
Working Files; Staging; Commit;
Working Files: You can edit the files.
Staging:After you enter git add <file>
, the file is now currently sitting in staging. Staging is a place where your files sit until you’re ready to commit them.
Commit:To commit to the repo.
git add <file>
file added to the stage;
git restore --staged <file>
file back to the working file from staging;
git commit -a -m"commit message"
file skipped over the staging step and is now committed this change.
Use Git III¶
Useful Video¶
How to Host a Website On Github Pages¶
How to Host a Website On Github Pages
Issues & Solutions¶
Windows11 cannot modify the file extension correctly (from .txt to .gitignore)¶
In Windows 11, if you change the extension of a .txt file to .gitignore, but the file is still showing as a .txt file, itβs likely because Windows File Explorer is set to hide file extensions by default. This means you may have only changed the file name and not the actual extension.
Hereβs how to fix it:
Show file extensions:
Open File Explorer. Click on the “View” tab at the top. Check the box that says “File name extensions.” This will display the full file extensions for all files.
Rename the file:
Locate the .txt file you want to change. Make sure you can see the full file name, including the .txt extension (e.g., filename.txt). Right-click on the file and select “Rename.” Change the file name to .gitignore, making sure to remove the .txt part. Verify the file type:
Ensure that the file is now named .gitignore and that there is no .txt extension left. This will convert the file into an actual .gitignore file rather than keeping it as a .gitignore.txt file.
After opening the
.gitignore
file in Notepad, enter*.txt
, which means ignoring all files in txt format. In this way, git will not track files in this format.