Below are step-by-step instructions for both Windows 11 and macOS using Git Bash (Windows) or Terminal (macOS). These instructions assume that you have already created and authenticated your GitHub account.
STEP 1: CREATE A NEW REPOSITORY ON GITHUB
- Go to GitHub.com:
- Log in to your GitHub account.
- Create a New Repository:
- Click on the “+” icon in the top-right corner and select “New repository.”
- Repository Name: Enter a name for your repository (e.g., my-new-repo).
- Description (Optional): Add a description.
- Public or Private: Choose whether the repository should be public or private.
- Initialize Repository: Do not check the box for “Initialize this repository with a README.”
- Add .gitignore and License: Leave these options unselected.
- Click Create repository.
STEP 2: SET UP A LOCAL REPOSITORY
FOR WINDOWS 11 (USING GIT BASH):
1. Open Git Bash:
Right-click in the Start menu and select “Git Bash” to open the terminal.
2. Navigate to Your Projects Folder:
Run the following command to navigate to the Projects folder:
cd ~/Documents/Projects
3. Create a New Local Repository Folder:
Run the following command to create a new directory for your repository:
mkdir my-new-repo
cd my-new-repo
4. Initialize the Git Repository:
Run the following command to initialize a new Git repository:
git init
FOR MACOS (USING TERMINAL):
1. Open Terminal:
You can open Terminal from the Applications > Utilities folder, or by searching for it in Spotlight.
2. Navigate to Your Projects Folder:
Run the following command to navigate to the Projects folder:
cd ~/Documents/Projects
3. Create a New Local Repository Folder:
Run the following command to create a new directory for your repository:
mkdir my-new-repo
cd my-new-repo
4. Initialize the Git Repository:
Run the following command to initialize a new Git repository:
git init
STEP 3: LINK THE LOCAL REPOSITORY TO GITHUB
1. Add the Remote URL:
Run the following command to link your local repository to the GitHub repository. Replace username with your GitHub username:
git remote add origin https://github.com/username/my-new-repo.git
2. Verify the Remote URL:
Run the following command to ensure the remote URL is correctly set:
git remote -v
STEP 4: COMMIT AND PUSH INITIAL CHANGES
1. Create a README File:
Run the following command to create a README.md file:
echo "# My New Repo" > README.md
2. Add Files to the Staging Area:
Run the following command to add the README file to the staging area:
git add README.md
3. Commit the Files:
Run the following command to commit the staged files:
git commit -m "Initial commit"
4. Push Changes to GitHub:
Run the following command to push the changes to the GitHub repository:
git push -u origin main
You have now successfully created and synced a new repository on GitHub and locally on your computer.