
Working with Git and GitHub
Welcome!
Note that this is a very basic guide to using Git and GitHub to work and connect to your projects.
Getting started
Have this git commands handy.
Commands are to be run without the <>
Download and Install Git for your machine here.
Open a GitHub account here.
Step 1: Start by creating a repository in GitHub
(1) set Repository name (give any name since this is training repo and can be deleted but name usually should suit the content)
(2) give it a Description (description is optional)
(3) leave as public
(4) ignore other settings. This is a basic guide just to get you started
(5) click on Create Repository
Additionally:
(6) click add/create file (dropdown), select add file
(7) to add a README file, type README as the name and type a more detailed description of the repository or whatever you want in the available space
(8) under the Commit new file space, type "Created a Read me file" or whatever you want
(9) leave others and Commit new file
(10) you can/should add a LICENSE by following the same steps above if you wish. MIT license is recommended.
(11) you may also create a .gitignore file. This file stores static files. You can read more here.
Step 2: Launch Git Bash from your machine
(1) cd into a directory. e.g. cd OneDrive/Desktop. You should see ~/OneDrive/Desktop $
(2) run <mkdir FirstGitRemoteConn> to create a folder/local git repository. FirstGitRemoteConn is a folder name so you may use any name of your choice
(3) run <cd FirstGitRemoteConn> to get into folder. Your should see this ~/OneDrive/Desktop/FirstGitRemoteConn $
(4) run <git init> to initialize FirstGitRemoteConn as a repository.
- You should now see ~/OneDrive/Desktop/FirstGitRemoteConn (master) $
Note: master is a branch. Read about branches here.
- You should also see a .git folder in your folder when viewed through File Explorer. If you don not see it, go to your file explorer, click view and tick the hidden items.
(5) Copy the https link from your newly created GitHub repository by clicking the dropdown in the Code button
(6) run <git remote add origin https link> to connect your remote/GitHub repository to local/Git repository
(7) run <git remote> -v to check if connection has been established.
- You should see origin <GitHub link> (fetch) and
- origin <GitHub link> (push). That means you are ready to pull (fetch) and push.
Step 3: Pull (or fetch) from remote (GitHub) repository
(1) while your Git Bash still shows this way, ~/OneDrive/Desktop/FirstGitRemoteConn (master) $
(2) run <git pull>
(3) run <git pull origin main> to fetch/pull from your remote repository's main branch to the master branch.
- If successful, you should see "From <GitHub link> * branch <branchname> -> FETCH_HEAD
- switch to the main branch by running git checkout main otherwise, you will need to merge pull requests to the main branch. Read about branches here.
I assume working from the main branch moving forward
Step 4: Push to remote (GitHub) repository
(1) in your FirstGitRemoteConn local folder, create your project file (Jupyter notebook, VS Code, etc)
(2) run <git add .> to stage the new file
(3) run <git commit -m 'Added main project file'> to commit your change(s)
(4) run <git push -u origin main> to push from local to GitHub repo. If you see this, "Logon failed, use ctrl+c to cancel basic credential prompt.",
- press ctrl+c
- follow the steps in this link.
Finally, keep making changes to your project file locally and keep pushing to your remote repository.