I have a folder with my project sources. How I can push this project into Github\'s repository?
I tried using this steps:
Hate to add yet another answer, but my particular scenario isn't quite covered here. I had a local repo with a history of changes I wanted to preserve, and a non-empty repo created for me on Github (that is, with the default README.md). Yes, you can always re-create the Github repo as an empty repo, but in my case someone else has the permissions to create this particular repo, and I didn't want to trouble him, if there was an easy workaround.
In this scenario, you will encounter this error when you attempt to git push
after setting the remote origin:
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:<my repo>.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.
As the error indicates, I needed to do a git pull
after setting the remote origin, but I needed to specify the --allow-unrelated-histories
option. Without this option, git pull
complains warning: no common commits
.
So here is the exact sequence of commands that worked for me:
git remote add origin <github repo url>
cp README.md README.md-save
git pull origin master --allow-unrelated-histories
mv README.md-save README.md
git commit -a
git push
Create a new repository
git clone <url>
cd "repositoryName"
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
Existing folder
cd existing_folder
git init
git remote add origin <url>
git add .
git commit -m "Initial commit"
git push -u origin master
Existing Git repository
cd existing_repo
git remote rename origin old-origin
git remote add origin <url>
git push -u origin --all
git push -u origin --tags
First, make a new repository on Github with your project name.Then follow the below steps..
1)git init
2)git add *
3)git commit -m "first commit"
4)git remote add origin https://github.com/yuvraj777/GDriveDemo.git
5)git push -u origin master
Another option if you want to get away from the command line is to use SourceTree.
Here are some additional resources on how to get set up:
Connecting to Bitbucket or Github
Cloning a remote repository
Creating a local repository
Adding an existing local repository
Git has been the version-control system of choice since its inception in 2005. About 87% of the developers use Git as their version-control system.
But if you have a project that is already existing and you want to push to Git in the remote server, follow along the below steps:
Go to the terminal of your project directory
You need to initialize your project git using git init
Create a .gitignore file and it is actually a text file that tells Git which files or folders to ignore in a project.
Stage your files using git add .
Commit your changes to your local repository with an appropriate commit message: git commit -m "my first commit"
In this step, you just need to create a repository in any one of the distributed version control systems like GitHub or Bitbucket
Use this Git command to link your local repository with that of the remote: git remote add <your-remote-name> <your-remote-url>
So, if your GitHub repo-url is https://github.com/your-github-username/new-repository.git, then the Git command becomes:
git remote add origin https://github.com/<your-github-username>/new-repository.git
Push your code to remote GitHub repository
git push origin master
Note: The git push
command requires two parameters: the name of the remote repository (origin) and the branch to push to (here master is the default branch for every repository).
Refer this blog for detailed information.
I found that stimulating an update in "natural" sequence was an easier route than force-pushing things.
Supposing that the repo is already created on github and you may have also put some stuff into the README.md .
On your computer, open terminal and git clone [repo URL]
You'll see a new folder will have been created bearing your repo's name. Feel free to rename it - doesn't matter.
Move your code, files etc into this folder. Edit the README.md if you have to.
Now open Terminal / command prompt, get inside that folder and do things as if you are making the next update to the repo:
git add .
git commit -m "v2"
git push origin master
Note: at the commit command git may reject, asking to configure the user email and password first. Follow the steps as given on screen, then run the commit command again.