How to push to new git branch not with Xcode - xcode

I've been using a git branch with a remote repo as well (Bit bucket)
I decided to create a new branch so ran this code
Directory= ~/tmp/merge/aaa> git branch iOSUI/beta
Directory= ~/tmp/merge/aaa> git checkout iOSUI/beta
Switched to branch 'iOSUI/beta'
Then tried to push
Directory= ~/tmp/merge/aaa> git push origin iOS7UI/beta
error: src refspec iOS7UI/beta does not match any.
error: failed to push some refs to 'https://xxx/repo.git'
So I tried to create a remote branch
Directory= ~/tmp/merge/aaa> git branch origin iOSUI/beta
error: there are still refs under 'refs/heads/origin'
fatal: Failed to lock ref for update: Is a directory
After that failed I tried through XCode by selecting push and then it pushed successfully to
'origin/iOS7UI/beta'
Again I tried through the command line 2 options
Directory= ~/tmp/merge/aaa> git push origin iOS7UI/beta
error: src refspec iOS7UI/beta does not match any.
error: failed to push some refs to 'https://xxx/repo.git'
and this option with the '/'
Directory= ~/tmp/merge/pixtr> git push origin/iOS7UI/beta
fatal: 'origin/iOS7UI/beta' does not appear to be a git repository
fatal: Could not read from remote repository.

The recent default push policy "simple" would prevent you to push to a non-existent branch (unless it is set to be your upstream branch).
You would need to do:
git push -u origin iOS7UI/beta
But check first if the branch from which you have created your iOS7UI/beta is pushed or up-to-date compared to the upstream repo.
If it is behind, that means iOS7UI/beta is based on a parent SHA1 which isn't yet pushed to origin.

Related

Git push error - failed to push some refs to <path>

I am trying to upload my code onto a repository I created on github but I get an error.
Assuming the URL of the repository is https://github.com/a, how do I go about uploading my code to my remote repository?
I tried the following commands on git bash after navigating INSIDE the folder I want to upload -
git init
(output - Reinitializing existing Git repository in C://(path)/.git/
git add.
(blank output)
git commit -m "Initial commit"
(output- On branch main. nothing to commit, working tree clean)
git remote add origin https://github.com/(path).git
(output - error: remote origin already exists)
git push origin master
(output - error:src refspec master does not match any
error failed to push some refs to https://github.com/(path).git)
Why is this happening and what could I do to push my code to my remote git repo? (I want to learn how to use git via cmd)
Thanks for reading my query!
note that you already have an remote repository configured as origin you must remove this configuration or rename then add the correctly repo.
the git command to remove remotes repositories by name is git remote remove ${repo_name}, in your case:
git remote remove origin
the git command to rename remotes repositories is:
git remote rename ${old_repo_name} ${new_repo_name}
then you can add an new remote with the name origin
git remote add origin https://github.com/(path).git
you can assume that the git command git remote add origin https://github.com/(path).git says to git configure an new remote repository into the current local repository, this remote config will "point" to the <URL> and the "alias" of this <URL> will be "origin" (or the name you specify between add and <URL>).
in this case <URL>=https://github.com/(path).git
With this you can have various remotes and specify then when you execute git push ${repo_name}
You can set an "default" upstream for git pull/status with git push -u ${repo_name}
You wrote:
git commit -m "Initial commit"
(output- On branch main. nothing to commit, working tree clean)
git push origin master
(output - error:src refspec master does not match any
Your init created a branch called main but you tried to push master, which doesn't exist. Try pushing main instead.

Unable to Git push to a remote branch (not master) from azure pipeline

I have been trying to do a Git Push from a bash task on Azure DevOps. I was already pushing the code to the master branch without any issues.
But now I have to push it to the dev branch, and for some reason, Git Pull works but not Git Push. These are the steps I followed. I tried various versions of this actually, but nothing worked.
git config --global user.email "xxx#gmail.com"
git config --global user.name "abc"
git pull https://PAT#github.com/repo.git HEAD:dev
git add $PROXYNAME
git commit -m 'Auto-checkin of $PROXYNAME proxy to Git'
git show-ref
git push https://PAT#github.com/repo.git HEAD:dev
The above worked when the push / pull had HEAD:master at the end.
This is the error I have been getting each time.
To https://github.com/repo.git
! [rejected] HEAD -> dev (non-fast-forward)
error: failed to push some refs to 'https://***#github.com/repo.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and 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.
Edited to add:
I have also tried with a checkout command - to checkout that dev branch, and no luck!
Result of git remote -v:
origin https://github.com/repo (fetch)
origin https://github.com/repo (push)
The latest error am getting is below:
error: src refspec dev does not match any
error: failed to push some refs to 'https://***#github.com/repo.git'
Could anyone please let me know what I need to do to get this working. This seems to be a recurring issue for me now :(
I believe you need to configure git remote to your correct repository.
The result of git remote -v should refer to your current directory remote association.
Start with git remote --help
Especially:
git remote set-url [--push] [] git remote
set-url --add [--push]
Here is a good tutorial on git remote.

Unable to update my GitHub from my Mac

Why am I unable to update my GitHub from my Mac?
git status produces the following:
On branch master Changes to be committed: (use "git reset HEAD
<file>..." to unstage)
new file: file.test
Untracked files: (use "git add <file>..." to include in what will be
committed)
.DS_Store
git push produces the following;
fatal: The current branch master has no upstream branch. To push the
current branch and set the remote as upstream, use
git push --set-upstream origin master
You need to git add ., then git commit -m "My commit message", then git push -u origin master.
That will set the upstream to the origin/master. Moving forward, just git push shall suffice
Git works through commits - which are basically snapshots of what your repository looked like at a given point in time. You need to commit the files to your repository before you can actually push them to GitHub.
So your first step is to add the files to the "Staging Area" with
git add file.text # you can do git add . but this will add all files which you may not always want
Now you can check the current status of the "Staging Area" with
git status
This will let you make sure that you are only committing the changes that you want added.
Now you can commit the changes. Committing will only 'save' the files that are in the Staging Area.
git commit -m "A useful description of what you did since your last commit"
Ok so now you're ready to push. Assuming you cloned from GitHub you can just run
git push origin master
But if you created this repository with git init you will need to tell git that you have a remote repository somewhere. Do this by running
git remote add https://github.com/<usernane>/<repo_name> origin
This origin is the name you would like to associate with the remote repository. 'Origin" is the most common but you may have other remotes like "backup" or "code_review" for different use cases.
Once you have added the remote repo, you can actually push to it with
git push origin master
Again, origin is the name for your remote repo and 'master' is a 'branch' name.
You can add the -u flag which will make it so that git assumes you want to push to origin. So in the future you would only need to run
git push
Listen to the error messages. :)
You currently have one untracked file, .DS_Store which I happen to know is a system file, so you may want to add that to your .gitignore
As for trying to push upstream, you need to set your upstream for each branch, so you simply need to type the command
$ git push --set-upstream origin master
then do a simple
$ git push
to send your changes to github.
If the branch you are pushing to online is ahead of you, then you may need to do a git pull to get grab the changes, before you do a git push.

How to do push for new repository?

I created new repository (git#github.com:derkode/ForvoClient.git) and did SSH Key, then:
git config --global user.email "my_email#mail.com"
git config --global user.name "my_nickname"
git config --global push.default simple
git init
git add *
git commit -m "First commit"
git remote add origin git#github.com:derkode/ForvoClient.git
But after: git push -u origin master
! [rejected] master -> master (non-fast-forward) error: failed
to push some refs to 'git#github.com:derkode/ForvoClient.git' hint:
Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git
pull') hint: before pushing again. hint: See the 'Note about
fast-forwards' in 'git push --help' for details.
What is it?
Your repo on GitHub already has a commit.
https://github.com/derkode/ForvoClient
This is normal when you create a repo with a README file.
You can fix this either by force pushing your local repo to GitHub, but you will lose the README file this way:
git push -u origin master -f
Or, you can merge the version on GitHub into yours and then push it back:
git pull origin master
git push -u origin master
Or, as #xbonez suggested, rebase your version on top of GitHub's version:
git fetch origin
git rebase origin/master
git push -u origin master
If you want to get rid of the commit that Github created for you with the README file, follow janos's answer. If you want to keep that commit, and push yours over it, simply pull down those changes and then push:
git fetch origin && git rebase origin/master && git push origin master

Getting error when trying to git push to remote branch (Heroku)

Hi I tried to push my local changes to heroku production but I am getting the following error
Zhens-MacBook-Pro:Dailymuses-Server-Side zaikshev88$ git push heroku-production master:master
To git#heroku.com:dailymuses.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git#heroku.com:dailymuses.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
The issue here is that when I tried to do a git pull, I was told that everything is up to date
Zhens-MacBook-Pro:Dailymuses-Server-Side zaikshev88$ git pull origin master
From github.com:mingyeow/Dailymuses-Server-Side
* branch master -> FETCH_HEAD
Already up-to-date.
What is the issue here and how can I resolve it?
Your push command is to remote heroku-production but your pull command is to origin. The non-fast-foward message means the history in your current repo differs from the Heroku remote; likely someone has pushed a branch with some merges or rebases.
I implore you to not use Heroku as the authoritative git remote. Assuming you are not, you can force push over the Heroku master branch to resolve this.
git push -f heroku-production master:master

Resources