I've trying to push my files into git, but it doesn't work.
This is what I've done before.
git init
git add .
git commit -m "Start"
git remote add origin git#github.com:user/repo.git
The first git push -u origin master works.
After changing some files and trying to git push -u origin master again
it doesn't work.
To git#github.com:denis89/gaw8d3.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git#github.com:denis89/gaw8d3.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Also git pull doesn't work, because of unmerged files.
Any ideas?
You will not be able to push because your head is behind the remote thus the non-fast-forward message. You must perform a git pull before you can push. A git pull actually performs a git fetch and then a git merge.
You say git pull does not work because of un-merged files. This is most likely caused by one of two things:
conflicts.
If you have conflicts you need to resolve them and then commit locally to merge.
you have uncommitted files that are conflicting with files you are attempting to pull.
In the second case you can't pull because the remote has a more up to date version of a file you have made changes to but have not committed your version and so git cannot even attempt to merge the versions.
You will have commit your version of this file and then try to merge again. If you don't want to commit those files you must stash them before you can pull.
In both cases a simple git status command will show you committed files uncommitted files and conflicts.
Related
How to initialize a git repository on a directory that contains a subdirectory that has git already initialized?
I am working on a MERN application and I have created a root folder "chatapp".
Inside the root directory, there are two sub-directories:
client
server
I am using React for the frontend and react comes with git already initialized.
I want to initialize git inside my root directory which contains the client subdirectory with git already initialized.
And when I run git init, it initialized well but when I run git add to stage the files for commit, it brings an error: screenshot of my code editor
I need to add both the client and server files to my git repository.
Do I need to first initialize git in the server file separately then merge or how do I add both files to the staging area?
How can I add do this without seeing the error to avoid conflicts in the repository?
Thank you,
You need to use Git Submodules and add the repo separately.
For example: git submodule add https://<GIT_HOST>/server.git server and git submodule add https://<GIT_HOST>/client.git client
Or, you could just not have those be Git repos.
I'm working on a small React project and have pushed its old version to the GitHub a couple days ago to this repo: Old repo
Since that time, I've made multiple changes to my project, so I decided to create a new repo and push the latest version of the app there.
The problem is that the old version of the project has been pushed to my new repo, I don't understand why. Can you help me to resolve this?
Please, tell me what is the mistake - why I'm pushing the old version of my app that even not exists on my computer?
Here is a link to my new repo: New repo
Steps I've made in Windows Powershell to push the project to new repo:
git init
git add -A
git commit -m 'Added my project'
git remote rm origin
git remote add origin https://github.com/Leocete/react-test-app.git
git push -u origin master
You're still in the middle of a rebase.
It stopped rebasing since there was/are conflicts.
Please fix your conflicts.
Then run git add -A && git commit -am "your message here"
After that you need to continue your rebase by using: git rebase --continue
If all went well you rebased your branch and are able to push the changes with git push -f. This will force push your branch since you've diversed from remote.. as #vincentm already said be warned since you're changing the history line.
You could use --force to overwrite the remote code. ( git push --force origin master )
Use it with caution (your repo is new, so i think it's not a problem, but avoid it on a repo with hundreds of commits :-) ).
I have some questions about gh-pages. I have a githab repository and project
Page as githubpages. In the project directory that I use the
Github repository created has git push, git pull, git build and
git deploy without problems. The site can be found at http://ux.example.com
call. Unfortunately, it is not possible to make the page using https://ux.example.com
call. In the settings, it is explicitly pointed out,
That it is not possible to call custom subdomains with https.
I have on another computer the repository via git clone
downloaded. Git pull, git push, git build works perfectly.
I suspect that the cause is the subdomain. How do I solve the problem?
With git deploy I get the following error message:
yarn run deploy
yarn run v0.27.5
$ gh-pages -d styleguide
fatal: attempt to fetch/clone from a shallow repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I want to backup my project, so I have tried initializing a rep with
git init
and then commit all files with
git add .
git commit -am "first commit"
and now I want to push it to a repository (which is not only locally stored).
I know I have to do something like
git push origin master
I know that master is the name of my branch, but what is origin?
Where are the files stored? Do I have to create a repository on GitHub, so the files can be stored on GitHub's servers or are there some Git servers which can store my files for free (I assume not :D)?
So do I have to first create the repository on GitHub and then connect my local project with the GitHub repository with
git remote <url_to_GitHub_rep>
Create a repository in github and copy the git url(Something Like https://github.com/username/gitname.git ).
Then
git init
git add .
git commit -m "First commit"
git remote add origin https://github.com/username/gitname.git
git remote -v
git push origin master
Then You Will Be Asked Your Github Username & Password.
Now Enter Github Username and Password.
The Files Will Uploaded to your repository.
Thank You.
First of all you need to be have an account.
The most popular way to back up projects with git is using remote git repo.
For the remote git repo, it can be setup on your own server, or it can be hosted on github, bitbucket etc.
The remote repo is the place where you really version control or backup your project. And the local git repo works as working copy for remote repo. You can connect remote repo with local repo with the situations:
Already has local repo (the situation as you have):
git add .
git commit
git remote add origin <remote repo URL>
git push -u origin master
Note:
origin is the default name for the remote repo (similar as master is default branch name), of cause you can use other names to replace origin.
-u (--set-upstream) option is set the tracking relationship between local master branch and remote master branch. You can find your local master is behind or ahead of remote master branch by git status.
Not has local repo:
git clone <remote repo URL>
cd <repo name>
git add .
git commit
git push origin master
Note: when you clone a remote repo locally, git will set the remote name as origin by default.
I have a Ruby on Rails project (versioned with git) that includes a number of external JavaScript dependencies that exist in various public GitHub repositories. What's the best way to include those dependencies in my repository (aside, of course, from just manually copying them in) in a way that allows me to control when they get updated?
git submodules seem like the perfect way to go, but it causes problems when switching among several branches, many of which don't contain the same submodules.
If git submodules are the best way to do it, I suppose my real question is: How can I use submodules among many branches without running into this problem all the time:
my_project[feature/new_feature√]$ git submodule update
Cloning into public/javascripts/vendor/rad_dependency...
remote: Counting objects: 34, done.
remote: Compressing objects: 100% (29/29), done.
remote: Total 34 (delta 9), reused 0 (delta 0)
Receiving objects: 100% (34/34), 12.21 KiB, done.
Resolving deltas: 100% (9/9), done.
Submodule path 'public/javascripts/vendor/rad_dependency': checked out '563b51c385297c40ff01fd2f095efb14dbe736e0'
my_project[feature/new_feature√]$ git checkout develop
warning: unable to rmdir public/javascripts/milkshake/lib/cf-exception-notifier-js: Directory not empty
Switched to branch 'develop'
my_project[develop⚡]$ git status
# On branch develop
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# public/javascripts/milkshake/lib/cf-exception-notifier-js/
nothing added to commit but untracked files present (use "git add" to track)
An alternative to submodules is the subtree merge strategy. Copied from that page (it has more info, this is purely for reference):
In this example, let’s say you have
the repository at /path/to/B (but it
can be an URL as well, if you want).
You want to merge the master branch of
that repository to the dir-B
subdirectory in your current branch.
Here is the command sequence you need:
$ git remote add -f Bproject /path/to/B
$ git merge -s ours --no-commit Bproject/master <2>
$ git read-tree --prefix=dir-B/ -u Bproject/master
$ git commit -m "Merge B project as our subdirectory"
$ git pull -s subtree Bproject master
I personally find this fiddly (I prefer submodules, even with the issus you've mentioned), although a lot of people swear by it.
Both this blog and this post reports the same warning:
This is because submodule deletion is not well supported at the moment. There has been a lot of discussion how to make git handle that better but no one implemented it so far. But it's on my ToDo list, so stay tuned ...
(said Jens Lehmann at the time, November 2010).
Right now (March 2011), I don't see (or I missed) any improvment on that front.
What would a git checkout -f -q develop do in your case?