Push an existing repository when creating a new repository always fail? - github

So every time I try to create a new repository and follow the Github instruction here.
…or push an existing repository from the command line
git remote add origin
https://github.com/menghaohsu/JavaAkkaCountWordInDirectory.git
git push -u origin master
It doesn't push the file in JavaAkkaCountWordInDirectory to Github but push repository. Can anyone help me with this?

Let me give you a few steps over here.
I assume you created your repo via GitHub.com web interface.
Locally you should have done all of the following steps prior to pushing the files to the remote.
git init --> This will initialize your local repo
git remote add origin {remote address}
git add {filename here | . } --> With this you add the file(s) to the staging area
git commit --> This command commits your changes (You have to add a message)
git -u push origin master
That should do the trick

Related

Files not appearing on github

I am new to web development and have just created my first project. I created a new repository on github and then did the following on git bash:
Moved to the working directory for my project
Initialized the git repository using git init
Added my files using git add .
Committed the files using git commit -m 'my message'
Added the github URL under code. on github by using git remote add origin 'my_url_name'
Pushed the code to github using git push -u origin master (also entered my passphrase correctly as I am using SSH)
Git Bash confirmed the upload and then nothing appeared on my repository on github
Note. I did get a message at the top of the repository saying "master had recent pushes x minutes ago: with a button that says "Compare & pull request" though the page just shows a message "There isn't anything to compare."
Am I missing a step?
The branch selected in your git is master. But in GitHub is main. To display your codes in GitHub, you need to change the Git branch to main.
First delete previous repository in Github and create a new , then act according to the following codes in the git :
git branch main
git checkout main
git merge master
git branch -M main
git remote set-url origin https://github.com/masoud8911/example.git
git push -u origin main
It could be that your local branch name is main not master. You can check this locally with:
git branch.
try instead:
git push -u origin main
Make sure you are selecting the correct branch on github. At the top of the repository, on the same line as "Go to file" "Add file" and "Code" on the far left is a button to select the branch. Make sure the branch is the same as the branch used as origin when the push was declared on Git Bash.

How to push changes to old repo to GITHUB after downloading it

I lost my PC data after hard-drive corruption. After that from my github repo i downloaded my code and made some changes and did npm install, but when i tried to push my changes to repo, it is saying there are no currently active repo to push.
How to push my new changes to my old repo?
You should have cloned the repo on your local machine, that way you would have the git initialized. But, for now, you can follow the below steps.
git init
git remote add origin <github repo url>
The first line would initialize the git repo and the second would point it to the online repo you already have.
You could have downloaded the repo with:
git clone <repo url>
but to answer your question:
git init
git add .
git commit -m "init"
git remote add origin <repo url>
you can then verify the remote url with:
git remote -v
after that check If your .gitignore file is there, if not create one and add node_modules/
after that just push it with:
git push -f origin master
just check whether you have set the remote origin correctly.
$ git remote show origin
$ git remote -v
use the above commands to check your remote URL. if it is not set correctly, set the URL again.
$ git remote set-url < your repo URL here >
hope this will work

How to delete GitHub blame history?

I'd like to delete the GitHub blame history that GitHub shows (tracking all changes made)
I am aware of how to how to roll back changes, but I am not trying to roll back any changes I have made, I am simply trying to delete this history of the changes.
Obviously, I do own the repository that I will be operating on (and am the sole owner)
If this is for all files of your GitHub repository, the simplest way would be to:
initialize a new local repository
add files from the original repo
add as remote the original repo GitHub URL
force push
That is:
git clone https://github.com/me/myrepo
git init myrepo2
cd repo2
git --work-tree=../myrepo add .
git checkout # -- .
git commit -m "Import myrepo"
git remote add origin https://github.com/me/myrepo
git push --force -u origin master

Error pushing code to Github repository

I'm trying to setup jekyll by following this setup. For that I created a public repository and under the same name on my computer cloned the project.
However once I try and push the code, it gives me following error -
fatal: 'aniruddhabarapatre.github.com' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I tried doing Git setup in case something got overridden, but am unable to finish the process and it hangs on
git credential-osxkeychain
Make sure you are pushing to the right github repo.
Its url should be
https://github.com/aniruddhabarapatre/aniruddhabarapatre.github.com
If git remote -v doesn't show this, do a:
git remote set-url origin https://github.com/aniruddhabarapatre/aniruddhabarapatre.github.com
And try to push again.
For the credential issue, see this answer, or this one, or (for checking how git is installed) this answer.
When you create a git repository add git ignore files, then it no more push unwanted files
Git global ignore
errors like this will occur when you try to push to a GitHub which you did not connected with the local repository you have in your machine. We can resolve this in a such way!
One: Delete your local repository and clone your GitHub project to your local machine($git clone ..url..) and now you can push any change directly to your GitHub account. If you do not want the original file from your local machine because you have some code on it you can move that to some where other than the directory you going to clone it. Then paste the content of your change inside newly cloned folder. Some time the issue/error may still persist so lets move to the second option.
Two: Here you mostly play with GitHub and follow this instruction since I did this many times.
From your terminal
To initialize the local directory as a Git repository
$git init
Add the files to your new local repo
$git add .
commit the file
$git commit -m "any comment you want to say"
Add the URL for the remote(GitHub) repository
$git remote add origin ..url..
Set the new remote
$git remote -v
Push the change
$git push -u origin master
Now if you go to your GitHub repo you will see your change.
While pushing the terminal might say pull first bla bla ... in that case you can force your push by saying
"$git push -f origin master"!!
Hopefully this will be helpful.

push my project to github

I followed these steps: https://help.github.com/articles/generating-ssh-keys
now, I want to create a folder in my github account, is called: "TODO_LIST", and push my project into this folder.
what I should do? I'm located in the folder I want to add.
should I need to do something like the next following?
$ git init
$ git add .
$ git commit -m 'first import'
$ git remote add origin git#github.com:alonshmiel/TODO_LIST.git
$ git push origin master
p.s, I have two SSH keys in my account because I push from two computers.
This is explained in the Create a Repo help page:
Every time you make a commit with Git, it is stored in a repository (a.k.a. "repo"). To put your project up on GitHub, you'll need to have a GitHub repository for it to live in.
[...]
Click New Repository.
Fill out the information on this page. When you're done, click "Create Repository."
[...]
git init
# Sets up the necessary Git files
git add README
# Stages your README file, adding it to the list of files to be committed
git commit -m 'first commit'
# Commits your files, adding the message "first commit"
[...]
git remote add origin https://github.com/username/Hello-World.git
# Creates a remote named "origin" pointing at your GitHub repo
git push origin master
# Sends your commits in the "master" branch to GitHub