I am very new to git and I am self learning it.
I have created a repository in github which has these two files .gitignore and README.md. only.
Now I have an angular project in a folder in my local.
I want to push my project to the newly created github repository, so i used the following commands in order--
after this I am getting the following error---
To https://github.com/Arpan619Banerjee/test-git-commands.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/Arpan619Banerjee/test-git-commands.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.
I understood that the .gitignore and README.md files that are present in my github repo is diff from what i have in local , so i have to pull the changes first and then merge it and then i can push it. But I tried doing that-- I executed the following commands in order, started from the very begining as i do not know how to proceed after getting the error, so I thought I will pull an dmerge the changes before pushing it.
git remote add origin https://github.com/Arpan619Banerjee/test-git-commands.git
git pull origin master
Then I got the following message. I do not know how to proceed after this-
error: The following untracked working tree files would be overwritten by merge:
.gitignore
README.md
Please move or remove them before you merge.
Aborting
I searched in Google I got this answer--
The problem is that you are not tracking the files
locally but identical files are tracked remotely so
in order to "pull" your system would be forced to
overwrite the local files which are not version controlled.
Try running
git add *
git stash
git pull
But here the local files are getting overwritten , I do not want this. I want my local changes to be pushed. How to resolve the merge conflict here to preserve my local changes.
Through Vs code git GUI i was able to merge my local changes, but i want to do it through cmd. Please help me.
How I solved this----
After getting that error while pulling from origin(i.e, my github repo url)
I went to my local folder manually edited and kept only the local changes-- i.e,
between <<<<<<<<<<<<<HEAD and =========
then i ran the following commands--
It worked!