fatal error in git hub when pushing in branch - github

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.

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.

Having trouble pushing up my projects to GitHub

I am having difficulty pushing up my code to GitHub.
I have a GitHub account and have created the repo:
cd into project folder
git init
Result:
Reinitialized existing Git repository in /Users/blakeflowers/Documents/fake-news-app/.git/
git remote add origin https://github.com/devnoob-flowers/shit-they-say.git
Result:
fatal: remote origin already exists.
git add .
Results: seems to do nothing
git commit -m "Practice Push"
Results:
On branch master
nothing to commit, working tree clean
git push -u origin master
To https://github.com/devnoob-flowers/shit-they-say.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/devnoob-flowers/shit-they-say.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
So clearly I have no idea what the heck is going on.
Once again im trying to push my code up to GitHub and eventually deploy the site using Github pages. just something im doing for practice.
I solved it by finding some terminal code but I don't understand it. Can anyone explain?
This solved my problem:
git fetch origin master:tmp
git rebase tmp
git push origin HEAD:master
git branch -D tmp

Unable to push files in git repository

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

Sync my Pull request with someone else commit some changes - Github

I sent a PR and someone else made some changes so it has 3 more commits and now I need to sync that PR with my local to continue working on some changes. How could I do to sync my local with the PR. Thanks
A pull request is basically just a designated branch on your fork of the repository. Update that branch (by rebasing its commits on top of those new commits) and the pull request will automatically update to show these changes.
First, you need access to the additional commits in your own fork of the project. To do so, you can add the upstream repository as an additional remote and fetch the commits from there:
git remote add <new-remote-name> <upstream-url.git>
git fetch <new-remote-name> <upstream-branch>
Then you can rebase your changes on top of the upstream changes:
git checkout <your-pr-branch>
git rebase <new-remote-name>/<upstream-branch>
git push <origin> <your-pr-branch>
You need to rebase your branch to reflect all the merged work of others in your PR. Here is how you can do this:
Let's say upstream is the name of the remote repository which you have forked, and origin is the name of your forked repository.
git pull --rebase upstream master
git push origin master
There can be merge conflicts sometime during rebasing. In that case, check the files in which conflicts are there using:
git status
The name of the files which are in red color are the files having conflicts. Resolve the conflict manually. After resolving, add the files using:
git add <filename> or //for each conflicted file
git add --all //to add all files at once
Once again check the status using the git status command. If all the files are shown in green that means they are resolved and you can now continue your rebase. Run the below command for continuing your rebase:
git rebase --continue
Once done, simply push the changes to your forked repo using:
git push -f origin master
Note: In case, you have not set the remote url of your upstream and origin, add them using following commands:
git remote add upstream <upstream-url>
git remote add origin <origin-url>

How to create a second distinct pull request from a GitHub fork?

I have a GitHub fork. I used it to create a pull request against upstream.
I'm trying to work on a second pull request. I don't want the second pull request to cross pollinate into the first pull request.
How do I configure things so I can work on the second pull request without contaminating the first full request?
The obvious answer (for me) is to create a second clone. GitHub does not allow that.
The next obvious answer (for me) is to create a branch. But Git does not allow me to configure it. I'm not allowed to create a branch and set its origin to my GitHub clone.
Here's the error when attempting to create a branch. Notice the pull fails, and I am not allowed to set its origin to my fork:
$ git checkout -b arm-aes
Switched to a new branch 'arm-aes'
$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=<remote>/<branch> arm-aes
Now try to fix it:
$ git remote -v
origin https://github.com/noloader/botan.git (fetch)
origin https://github.com/noloader/botan.git (push)
upstream https://github.com/randombit/botan (fetch)
upstream https://github.com/randombit/botan (push)
$ git branch --set-upstream-to=https://github.com/noloader/botan.git
error: the requested upstream branch 'https://github.com/noloader/botan.git' does not exist
...
$ git branch --set-upstream-to=https://github.com/noloader/botan
error: the requested upstream branch 'https://github.com/noloader/botan' does not exist
...
But Git does not allow me to configure it. I'm not allowed to create a branch and set its origin to my GitHub clone.
Sure it does:
git fetch upstream
git checkout -b newbranch upstream/master
Make sure you have a git remote upstream referencing the original repository (the one you have forked).
git remote add upstream https://github.com/<user>/<repo>