Git Tutorial
Git Tutorial
A Source Control Management (SCM), i.e. a tool, which allows you to manage and track
changes to files over time, making it possible to revert to a file.
1. Installation: https://git-scm.com/downloads
a. Windows user: git is not automatically installed.
b. Mac user: git is typically already installed.
Note: when git is installed, git Bash is automatically installed.
2. Open Git Bash (or any terminal of your choice).
3. Navigate to the folder (directory) that you want to set as your local repository.
Ex. user/documents/winter2023/gitRepos
4. Create a repository:
a. $git init //the command with no parameters initializes the current directory
(i.e. folder) as the repository.
b. git init nameOfRepo //the command with parameter (fileName) creates and
initializes a new repository (i.e. subdirectory/subfolder) in the current directory.
You can name it whatever you please.
8. $git status //to show current branch and commits. It also allows you to see tracked vs.
untracked files. It is a very useful command!
or use a text editor of your choice and save it in your git repository (Avoid using
Microsoft word!):
iv. Visual Studios
v. Notepad
vi. Notepad++
enter INSERT mode = click the letter I Save = click ctrl and the letter O at the same time,
Save & quit = click esc then type :wq and click Enter Exit = click ctrl then type x
2. Inside the file, write code to print the text “Hello World!”
Print(“Hello World!”)
3. Save the file:
Ctrl + O then click enter
$git status //use git status to help you see staged files and unstaged files.
a. $git add fileName // track one file (move into the staging area)
$git status
b. $git rm --cached fileName //untrack a file (move back into working directory.
$git status
b. $git status //enter git status to see what changed after committing.
#save file
Ctrl + O then click enter
15. Setup a new remote repository (go to the new repo page):
Notes:
a. Setting a description is helpful and a good practice.
b. Make it public (it can be searched and any can see it) or private (it cannot be
searched, but you can still share it amongst collaborators).
c. (optional) add readME file and/or a .ignore file. Adding a readMe file is a very
good practice, it helps others who are interested in what your repository is all
about. These are optional because they can be added at any point. For example,
if you decide later that there is a file you don’t want to git to track, you can
manually create a simple .ignore file.
17. Check your pushed repository on GitHub: (it should be synced on GitHub)
*re-click the name of the repository you created on GitHub and your pushed data
should appear.
a. Review the commits in your GitHub repository
b. Add a file directly on GitHub
c. Edit a file directly on GitHub
20. Cloning:
*The act of copying a remote repository then downloading into our local git
repository so we can make commits to it and push it back.
a. $git clone urlLink