Do you need a refresher on git? Go through Codecademy's git
course.
-
Using your terminal/command line, get inside the folder where your project files are kept:
cd /path/to/my/codebase
. → You cannot do this simply by opening the folder normally, you must do this with the command line/terminal.
→ Do you need a refresher on using your command line/terminal? I've compiled my favorite resources here. -
Check if git is already initialized:
git status
If you get this error message: fatal: Not a git repository (or any of the parent directories): .git, that means the folder you are currently in is not being tracked by git. In that case, initialize git inside your project folder and make your first commit:git init git add . git commit -m "initial commit"
→ If you get another error message, read carefully what it says.
- Is it saying git isn't installed on your computer by saying that the word 'git' is not recognized?
- Is it saying that you're already in a folder or sub-folder where git is initialized?
- Google the error output to understand it, and to figure out how to fix it.
-
Login to your Github account.
-
At the top right of any Github page, you should see a '+' icon. Click that, then select 'New Repository'.
-
Give your repository a name--ideally the same name as your local project. If I'm building a travel application, its folder will be called 'travel-app' on my computer, and 'travel-app' will be the Github repository name as well.
-
Click 'Create Repository'. The next screen you see will be important, so don't close it.
The screen you should be seeing now on Github is titled 'Quick setup — if you’ve done this kind of thing before'.
-
Copy the link in the input right beneath the title, it should look something like this: https://github.com/yourname/yourproject.git
This is the web address that your local folder will use to push its contents to the remote folder on Github. -
Go back to your project in the terminal/command line.
-
In your terminal/command line, type
git remote add origin [copied web address]
Example: git remote add origin https://github.com/yourname/yourproject.git -
Push your branch to Github:
git push -u origin main
-
Go back to the folder/repository screen on Github that you just left, and refresh it. The title 'Quick setup — if you’ve done this kind of thing before' should disappear, and you should see your files there.
Anas@DESKTOP-PQVUR5J MINGW64 ~/3D Objects
$ git init
Initialized empty Git repository in C:/Users/Anas/3D Objects/.git/
Anas@DESKTOP-PQVUR5J MINGW64
/3D Objects (master)$ ^[[200
bash: $'\E[200~': command not found
Anas@DESKTOP-PQVUR5J MINGW64 ~/3D Objects (master)
$
Anas@DESKTOP-PQVUR5J MINGW64 ~/3D Objects (master)
$ git add .
warning: adding embedded git repository: static
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint: git submodule add static
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint: git rm --cached static
hint:
hint: See "git help submodule" for more information.
Anas@DESKTOP-PQVUR5J MINGW64 ~/3D Objects (master)
$ git commit -m "initial commit"
[master (root-commit) e0fc14d] initial commit
2 files changed, 1 insertion(+)
create mode 100644 desktop.ini
create mode 160000 static
Anas@DESKTOP-PQVUR5J MINGW64 ~/3D Objects (master)
$ git remote add origin https://github.com/anasrawuthar/djangoweb.git
Anas@DESKTOP-PQVUR5J MINGW64 ~/3D Objects (master)
$ git push -u origin main
error: src refspec main does not match any
error: failed to push some refs to 'https://github.com/anasrawuthar/djangoweb.gi
t'
Anas@DESKTOP-PQVUR5J MINGW64 ~/3D Objects (master)