Git 101 - How to connect your project to GitHub
- thetperson314
- Jul 30, 2021
- 2 min read
Updated: Aug 25, 2021
Connect Your Project
If using the new GitHub go to the bottom
To make this easier to understand lets make our user name 'NerdHead' and our repository (git project) name to 'CoolGame'
Now our project Url will be: https://github.com/NerdHead/CoolGame
After downloading and installing Git on your computer open the file location right click and open the 'Git Bash Here'
Now write the following (If using the new GitHub go to the bottom)
git init
git add .
git commit -m “First Commit”
git remote add origin https://github.com/NerdHead/CoolGame
git push --set-upstream origin masterIf comment 4 not working make sure that your are on the right branch (master) by using
git branchIf you are on the master branch use
git fetch
git checkout mainThan you can continue from the 4th stage again
* take note that the last commend makes the main branch to be main, some other websites might make it with another name (like 'master' let's declare as wrong branch)
Now when you go to your GitHub project page and hit refresh you will see all of your files.
Fixing git pus
If you can't see your files that means that your filed are in another branch (probably because you used another name instead of main in stage 5).
To fix this just combine the branches use:
git fetch
git checkout main
git merge masterThis might not work, if so use:
git checkout master
git branch main master -f
git checkout main
git push origin main -fIf using the new GitHub
There is a problem with the new update to GitHub that might cause some problems for you, the GitHub main branch is called main but the Git main branch is master by default.
to fix this all you need to do it to switch to the main branch before adding anything to the git.
your code will look like this:
git init
git checkout -b main git pull https://github.com/NerdHead/CoolGame main git fetch
git add .
git commit -m “First Commit”
git remote add origin https://github.com/NerdHead/CoolGame
git push --set-upstream origin main