Process for Initial Git push

An overview on how to do an initial Git push when creating a new project locally.

Initial Git push to repository

1. Navigate to Your Project Folder

cd /path/to/your/project

2. Initialize a Git Repository (if not already initialized)

git init

This creates a hidden .git folder inside your project, making it a Git repository.

3. Add a Remote Repository on GitHub

(a) Create a repository on GitHub:

Go to GitHub.

Click the + (plus sign) in the top-right corner and select New repository.

Enter a name for your repository and click Create repository.

Copy the provided remote URL (e.g., https://github.com/yourusername/your-repo.git).

(b) Link Your Local Repository to the GitHub Repository:

git remote add origin https://github.com/yourusername/your-repo.git

4. Stage and Commit Your Files

git add .

git commit -m "Initial commit"

5. Push to GitHub

If your repository has a default branch main (or master), push with:

git branch -M main # Ensures your branch is named 'main'

git push -u origin main

If GitHub gives you an error like fatal: remote origin already exists, use:

git remote set-url origin https://github.com/yourusername/your-repo.git

Then try pushing again.

Future Synchronization (Keeping Your Repo Updated)

After making changes in your project, use:

git add .

git commit -m "Describe your changes"

git push origin main

To pull the latest updates from GitHub (if working across multiple devices or with others):

git pull origin main

All rights reserved.