How to use Git on Windows and Linux using terminal

In this blog, we are gonna learn all the commands to use Git on our project. First of all, navigate to the project directory using the $cd path/to/the/project and then follow the steps below.

Step 1: Initialize git (if not already)

Run this (only once per project):

git init

Step 2:Add your remote GitHub repo

Replace <your-username> and <repo-name> with your actual GitHub details. Example shown for your repo Neura:

git remote add origin https://github.com/<your-username>/Project.git

Example for you:

git remote add origin https://github.com/Zyro/Project.git

Step 3: Add your project files

Add all your project files except those ignored by .gitignore:

git add .

If you haven’t added a .gitignore yet, create one before running that (I can give the exact code again if needed).

Step 4: Commit the files

git commit -m "Initial commit: add Neura startpage"

Step 5: Push to GitHub

Push everything to your main branch (replace main with master if your repo uses that):

git branch -M main
git push -u origin main
That’s it!
Now refresh your GitHub repo page — you should see all your project files online.

⚙️ Basic Workflow Commands

# 1. Check what files you've changed
git status

# 2. See exactly what you changed (optional but helpful)
git diff

# 3. Stage your changes for commit
git add .                          # Add ALL changes
# OR
git add filename.txt              # Add specific files
# OR  
git add src/                      # Add a specific folder

# 4. Commit your changes
git commit -m "Your commit message"
# OR (for longer messages)
git commit

# 5. Push to GitHub
git push origin main              # if your branch is called 'main'
# OR
git push origin master            # if your branch is called 'master'

But sometimes we may run into an error like this:

$ git push -u origin main To https://github.com/zyro/Project.git ! [rejected] main -> main (fetch first) error: failed to push some refs to 'https://github.com/zyro/Project.git' hint: Updates were rejected because the remote contains work that you do not hint: have locally. This is usually caused by another repository pushing to hint: the same ref. If you want to integrate the remote changes, use hint: 'git pull' before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
The message basically says:
“Your GitHub repo already has something (like a README or LICENSE), but your local repo doesn’t. You must sync first.”

Here’s how to fix it cleanly ๐Ÿ‘‡

๐Ÿงฉ Option 1 — You want to keep what’s on GitHub (README, LICENSE, etc.)

Do this:

git pull origin main --rebase
git push -u origin main

That tells Git: “Pull the existing files (README, LICENSE) and apply my commits on top,” then push everything back.

๐Ÿงจ Option 2 — You want to overwrite GitHub completely (keep only your local files)

⚠️ This will delete what’s currently on GitHub (like the auto-created README or LICENSE). Run:

git push -u origin main --force

After that finishes successfully, you can go to

๐Ÿ‘‰ https://github.com/zyro/Project and you should see all your local files uploaded.


๐Ÿ” How to push updates next time

Whenever you work again, here’s your normal workflow:

  1. Open your terminal inside your project folder (Git remembers the repo, so no need to run git init or remote add again)
  2. Stage changes:
    git add .
  3. Commit changes:
    git commit -m "Describe what you changed"
  4. Push to GitHub:
    git push

That’s it. If you ever pull updates (e.g., you edited something directly on GitHub), use:

git pull
Quick tip combo:
When working normally:
git status
git add .
git status
git commit -m "Update stuff"
git push
This way, you can confirm what’s about to be committed.

๐Ÿ“ The Two Ways to Write Commit Messages

1. Short Message Only (what you're familiar with)

git commit -m "Fix login bug"

2. Both Short AND Long Message (what you're looking for)

Just commit without the -m flag:

git commit

This will open your default text editor (usually Vim, Nano, or VSCode) where you can write:

Fix login issue with expired tokens

- Updated token validation logic to handle expiration gracefully
- Added proper error messages for expired tokens
- Fixed race condition in token refresh
- Resolves issue #123

Co-authored-by: developer@example.com

Format Rules:

  • First line: Short summary (50 chars or less)
  • Blank line: Mandatory separation
  • Rest: Detailed explanation, bullet points, references, etc.

Pro Tips:

Set your preferred editor:

# For VSCode
git config --global core.editor "code --wait"

# For Nano
git config --global core.editor "nano"

# For Vim (default)
git config --global core.editor "vim"

Commit with both messages in one command:

git commit -m "Short title" -m "Long description here"

View both messages:

git log --oneline          # Shows short messages only
git log                    # Shows full commit messages
git show <commit-hash>     # Shows everything about a specific commit
Post Comment

Comments