3

I am trying to push my local code(my portfolio into my new Github repository. So created new repository. It says:

git remote add origin https://github.com/ex_username/ex_name.git
git branch -M main
git push -u origin main

Before pushing this repository, I was working on remote repository(which is another repository on my github) by making changes etc. I used to push: git push origin main

The issue is when I am trying to push my new local folder(which is my portfolio) , the previous repository that I was working on github being pushed together

How can I push my existing folder separately into my new repository?

Here is a clarification, I was working on these repos on Github: enter image description here

and here is next one. This repo is in Desktop/Project/20172018: enter image description here

Currently I have "My Portfolio" folder that I want to push into new repo on Github. When I created new repo and pushing the local folder, then above existing repos are being pushed together: enter image description here

What I want is this, just My Portfolio repo enter image description here

6
  • 2
    what is the previous folder? sorry not really clear to me....
    – OznOg
    Commented Apr 23, 2021 at 18:15
  • @OznOg It is another repository in my github. So I was working in existing repo in Github and while trying to add new repo and push local folder, then previous folders are being pushed together Commented Apr 23, 2021 at 18:36
  • What does it mean to be "pushed together"? Can you explain more about what you're trying to do and what you're seeing on your screen, things like git commands and the output? It isn't altogether clear what the problem is here. Commented Apr 23, 2021 at 18:39
  • @LasseV.Karlsen added with pictures for clarification Commented Apr 23, 2021 at 20:00
  • @OznOg added pics of repos Commented Apr 23, 2021 at 20:00

4 Answers 4

3

First In local, in your new directory initiate git and then add and commit files to git using the below commands.

  • git init
  • git add .
  • git commit -m "initial commit"

Second, create a new empty repo and then use the below commands in your project terminal to push the local repo to the remote repository.

incase if you're not on the branch main execute the below command (optional)

  • git branch -M main

Finally

  • git push -u origin main
2

When you create a new GitHub repo they provide you with 2 option of pushing data:

  1. create a new repository...
  2. push an existing repository

You chose the second one, but the folder that contains all your projects is not a git repository yet, that's why you are having trouble pushing data.

Try doing the steps provided in the first option as to create a new repository for all your existing projects.

0

Try using git checkout -b <branch-name>, this should create a new branch.

0

First, you need to create an empty repository on GitHub with the same name as your folder.

Second, you need to initialize your folder as a Git repository and connect it to the GitHub repository. You can do this by opening a terminal and navigating to your folder. Then, type the following commands:

git init # This will initialize your folder as a Git repository
git remote add origin https://github.com/your-username/your-repository-name.git # This will link your local repository to the GitHub repository

Third, you need to add and commit your files to the local repository and push them to the GitHub repository. You can do this by typing the following commands:

git add . # This will add all the files in your folder to the staging area
git commit -m "Your commit message" # This will commit your changes with a message
git push -u origin master # This will push your changes to the master branch of the GitHub repository

Finally, you can check your GitHub repository online and see if your files are uploaded successfully. Note:Folder and repository name must be same

Not the answer you're looking for? Browse other questions tagged or ask your own question.