Unable to push files in git repository - github

I am trying to push my files using git bash to online git repository using this command.
$ git push -u origin master https://github.com/SMAmmar/git-test.git
But after using it i am getting this error
fatal: invalid refspec 'https://github.com/SMAmmar/git-test.git'
How can I solve this problem? I am a newbie when using github so please elaborate what you guys are telling me to do.

From git push
git push <repository> [<refspec>…]
The "remote" repository that is destination of a push operation.
This parameter can be either a URL (see the section GIT URLS below) or the name of a remote (see the section REMOTES below).
So yes, git push can take a URL
But the order is important:
where you push (the URL or remote name)
what you push
In your case:
git push -u origin master
git push -u https://github.com/SMAmmar/git-test.git master
But not both origin and https://github.com/SMAmmar/git-test.git
The first form is preferred. Once that first command is working, a simple git push will be enough.

git push doesn't take a URL. Instead it takes the name of a remote repository that you've previously set up, that's origin, and a branch to push. origin is automatically set up when you git clone a repository.
If you run git remote -v you should see something like this:
origin https://github.com/SMAmmar/git-test.git (fetch)
origin https://github.com/SMAmmar/git-test.git (push)
If you see some other URL, use git remote set-url origin https://github.com/SMAmmar/git-test.git to make origin point at that URL.
Then git push origin master says to push your master branch to the master branch on the repository identified by origin which is https://github.com/SMAmmar/git-test.git.
See also
Working With Remotes
Managing Remote Repositories

Related

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

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

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

fatal error in git hub when pushing in branch

I want to push to a branch which is not master. That is what I did:
git init
git add .
git commit -m "first"
git push origin second (second is the name of a branch) but it say
fatal: origin does not appear to be a git repository.
fatal: could not read from remote repository.
Please sure you have the correct access rights and the repository exists.
Last night I could do that and in the morning suddenly it does not recognize my branch! it does not show my branch when I do git branch, it only shows a master branch. But why I experience this problem sometimes?
Thanks :)
First, make sure you are in the right branch: if git branch doesn't list 'second', you can create it:
git checkout -b second
Actually "second" branch exists and I can see it on the github site
Then:
git checkout -b second --track origin/second
(a git fetch origin might be in order first)
Then, make sure the remote 'origin' exists:
git remote -v
And then, push and set origin/second as upstream branch of your local branch second.
git push -u origin second
(See "Why do I need to explicitly push a new branch?" for more)
try
git pull origin master
before
git push origin master
I had the same error and it worked for me.

github fork confusion

I followed this https://help.github.com/articles/fork-a-repo post to clone a repository locally. After doing that another developer created a branch to the main repository and added some features to that branch. My question is
How do I get that branch into my fork.
Can I get that missing branch again to my local using git pull upstream/missing_branch command?
Thank you
You need to add a remote repo 'upstream' in the local repo (which has for origin your fork)
(git remote man page)
git remote add upstream url://upstream/repo
The OP opensourcelover mentions seeing this:
git remote -v,
origin git#github.com:username/project.git (fetch)
origin git#github.com:username/project.git (push)
upstream git#github.com:username/project.git (fetch)
upstream git#github.com:username/project.git (push)
If your origin is the same as your upstream remote repo, you can replace that url by the https one for that upstream:
git remote set-url upstream https://github.com/originalDevName/originalRepoName
That way, you can git fetch upstream and get the new branch.
If you need to work on that new branch, you can now declare it:
git branch -u upstream/foo foo
See "How do you make an existing Git branch track a remote branch?".

How do I change the remote source of my github repo?

I forked a repo and set everything up on my local machine. However, when I do 'git remote -v' it shows the original repo as my fetch and push source. I want it to by from my forked repo. How do I change it over to that without starting all over? And then, how do I add an upstream to the original repo?
From the git remote man page:
git remote set-url origin https://github.com/user/forkname
git remote add upstream https://github.com/maintainer/reponame
See also the examples of GitHub: Changing a remote's URL.
set-url
Changes URL remote points to.
You will then be able to fetch from upstream, and push to origin:
See "What is the difference between origin and upstream in Github".