How to add existing code to a newly created GitHub branch?

Step-by-step Instructions

1. Create a new GitHub repo

Go to: https://github.com/new

  • Set the repository name
  • Leave it empty (no README, .gitignore, etc.)
  • Create the repo

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

2. Initialize Git locally in your project folder

In your project folder:

cd /path/to/your/project
git init
git checkout -b new-branch-name  # Create and switch to a new branch

3. Add and commit your code

git add .
git commit -m "Initial commit on new branch"

4. Connect to the new GitHub repo

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

5. Push to the new branch

git push -u origin new-branch-name

That’s it! Your code is now uploaded to the new GitHub repository on a custom branch