How to clone my existing rails app - ruby-on-rails

I have a rails app that on my local development machine and I want to copy it and have a sort of starting point in case I don't want to start over from scratch later for future projects. Is there a rails command I can use to "clone" it or should I simply copy and paste the directory?

There is no rails command to clone your app. But you can install git on your system and create a git repo to do what you want easily. To do this go to your rails app root and execute
git init
git add .
git commmit -m "Your commit message"
You can then continue working and commit your changes as needed or discard all or individual changes. You can also clone your app with the git clone commmand.

Related

how to add existing non-git project to bitbucket

I created a project using angular cli. Project is in directory dw-ng2-app and it has several files generated by angular cli. I want to create a Bitbucket repository for this. My confusion is, when I create a repository in Bitbucket, it gives me 3 options
I create a README and .gitignore file. I cannot use this option as
then when I try to sync the local project with repository, I get
error that there is no common history
I selected option of starting
from scratch. The web page listed the commands I should run to clone
and upload, eg git clone git#bitbucket.org:username/angularcli.git
but this creates a new directory on my local machine named
angularcli which has .git directory. I am not sure if I can use this
option as my project is in different directory and moving it to
angularcli directory might affect it (not sure)
3rd option is to
mention that I have an existing project. Then I am prompted to use
the command git remote add origin
ssh://git#bitbucket.org/username/angularcli.git but that doesn't
work as my current project directory is not a git repository
How can I move the angular cli project to bitbucket? Should I have created the repository first and then created angularcli project in the generated directory?
There are a couple of ways to do this, but the simplest may be to simply make your current project directory, a git repository.
Go to your project directory
cd dw-ng2-app
Initialize git repository
git init .
Add your current project to be tracked
git add --all
Make your initial commit
git commit -m "Initial commit for Angular project"
At that point, you can use the third, "existing project" option within BitBucket.
After you've created a new repo there, you can see its URL and use that to track your new repository with your local one
git remote add origin https://username#your.bitbucket.domain:7999/yourproject/repo.git
git push -u origin master
[Here's a complete writeup from BitBucket if you need.][1]
note - I used git add . originally in my example, and BitBucket recommends git add --all. Either of these will work fine in your case.
[1]: https://confluence.atlassian.com/bitbucketserver/importing-code-from-an-existing-project-776640909.html
If you've created project using angulat-cli then it automatically created project with git initialisation. It also commits initial changes locally.
So you just have to add remote origin and push the content.
-If repository is not initialise as git repository then:
cd dw-ng2-app
git add --all
git commit -m "commit message"
git push -u origin master
-If already initialise with git repository.
First of all go to directory dw-ng2-app : cd dw-ng2-app
add remote to your repository.
git remote add bitbucket https://username#your.bitbucket.domain/yourproject/repo.git
push the changes:
git push -u origin master
here's master is name of branch in which you want to push the content.

Branch Then 'Reset' Rails Git Repository

I have a bit of a tricky problem. I restarted a current rails project from scratch in a new folder because I was redoing the app as a personal exercise. We've run into some issues on the 'official' version and now need to restart the project.
The problem is that we've been using git to keep track on the official project but I haven't been using it for my personal version.
I've branched the official git master repository using
git checkout -b restart_app
Now I'd like to clear out all the code in that branch and replace it with my personal version. I've tried to google the best approach to doing so but found some differing answers and I'm pretty new to working with git so I thought I'd put up a question here. What would be the best practice/solution for approaching this problem?
"I want replace all the files in restart_app with files from a different project folder"
Delete and replace the files by the ones you want.
The best practice is to do a git rm * first, then add your files, git add and commit.
A nice trick, you can use the --work-tree option of git:
git checkout restart_app
git rm -rf .
git add -A .
git commit -m "empty restart_app"
git --work-tree=/path/to/untracked/code add .
git commit -m "add new code"

How to upload a project to GitHub

After checking How can I upload my project's Git repository to GitHub?, I still have no idea how to get a project uploaded to my GitHub repository.
I created a repository and want to upload my project to it.
I've looked on the repository page for an upload button of some kind, but I haven't seen anything of the sort.
I've looked at the links provided so far, but I'm still getting nowhere. They mention command line; is that Windows command line or Git Bash? Because I can't get either to do anything.
I also tried using the Git GUI, but when I select the folder I want it says that it's not a Git repository...does it need to be zipped up? I tried adding the .gitconfig file in the folder, but it doesn't make a difference.
GitHub released a native Windows client which makes all the below steps redundant.
You can also use Sourcetree to get both Git and Mercurial setup on Windows.
Here is how you would do it in Windows:
If you don't have Git installed, see this article on how to set it up.
Open up a Windows command prompt.
Change into the directory where your source code is located in the command prompt.
First, create a new repository in this directory git init. This will say "Initialized empty git repository in ....git" (... is the path).
Now you need to tell Git about your files by adding them to your repository. Do this with git add filename. If you want to add all your files, you can do git add .
Now that you have added your files and made your changes, you need to commit your changes so Git can track them. Type git commit -m "adding files". -m lets you add the commit message in line.
So far, the above steps is what you would do even if you were not using GitHub. They are the normal steps to start a Git repository. Remember that Git is distributed (decentralized), meaning you don't need to have a "central server" (or even a network connection), to use Git.
Now you want to push the changes to your Git repository hosted with GitHub. You do this by telling Git to add a remote location, and you do that with this command:
git remote add origin https://github.com/yourusername/your-repo-name.git
*Note: your-repo-name should be created in GitHub before you do a git remote add origin ...
Once you have done that, Git now knows about your remote repository. You can then tell it to push (which is "upload") your committed files:
git push -u origin master
Follow these steps to upload a project to GitHub:
git init
git add .
git commit -m "Add all my files"
git remote add origin https://github.com/yourusername/your-repo-name.git
Upload of project from scratch require git pull origin master.
git pull origin master
git push origin master
git push --force origin master
if you have problems uploading!
Here I explain how I did it on Windows.
Make sure to install Git and GitHub.
After installation is complete, open Git Bash.
So a window like below is going to pop up:
Go ahead and type cd ~ to make sure you are in the home directory. You can check the address that you are in it by typing pwd;
Now you need to create a GitHub account. After creating a GitHub account, go ahead and sign in.
After you signed in, on the top right click on the + and choose “New Repository”
Then in the opened window, type the name that you wish to have for the repository in the “Repository name” box. Add “Description (optional)” if you like, and mark “Initialize this repository with a README”. Then click on “Create repository”.
Now go to your C drive; create a new folder and name it “git”. Now go to the “Git Bash” window; change the directory to c drive by typing cd ~; cd /c.
If you type ls there it would show you the folders there. Make sure it shows the Git folder there:
Now go back to the browser; go to your GitHub page, click on the repository that you made, click on “Clone or download”, and copy the address that shows there (by choosing copy to clipboard).
Now going back to “Git Bash”. Use the command cd git to go to the git folder; now write the following commands to connect to your GitHub (enter the username and password of your GitHub when it asks you):
git config --global user.name "Your Name"
And then: git config --global user.email youremail#domain.com.
Next type: git clone (URL), instead of the (URL), type the address of the GitHub repository that you copied from your GitHub page; (e.g., git clone https://github.com/isalirezag/Test.git).
Now if you do ls command you will see your repository there. If you also open the Git folder that you have in your window you will see that your repository is added as a folder.
Now use the cd command to go to the repository: cd Test
Go ahead and copy and paste any files that you want to put in this repository in that folder.
In order to transfer the files to your repository you need to do following now:
Type git
add filename (filename is the file name that you want to upload) or you can type the command below if you want to add all the files in the folder:
git add .
Then type: git commit -m "adding files". And then: git push -u origin master .
And then you should be all set. If you refresh your GitHub account, the files should be there :)
Follow these steps to upload your project to GitHub:
git init
git add .
git commit -m "Add all my files"
git remote add origin https://github.com/yourusername/your-repo-name.git
Upload of the project from scratch requires git pull origin master.
git pull origin master
git push origin master
If any problem occurs in pushing, use git push --force origin master.
Follow these two steps:
Create the repository online using the link: https://github.com/new
Then link your local repo to the remote repo using the command: git add remote origin https://github.com/userName/repo.git
Here the repo.git will be your newly created remote repo.
This will work like a charm. No need to worry about the SSH or HTTPS ways. I first faced the same issue and spent hours for solution.
But this worked for me.
Easy-to-follow steps: git pull origin master or main will give a fatal error:
Couldn't find remote ref main
So below steps will work just fine.
git init
git add .
git commit -m "initial commit"
git remote add origin https://github.com/yourusername/your-repo-name.git
git branch -M main
git push -u origin main
This worked for me;
1- git init
2- git add .
3- git commit -m "Add all my files"
4- git remote add origin https://github.com/USER_NAME/FOLDER_NAME
5- git pull origin master --allow-unrelated-histories
6- git push origin master
Create a new repository on GitHub. To avoid errors, do not initialize
the new repository with README, license, or gitignore files. You can
add these files after your project has been pushed to GitHub. Open
Terminal (for Mac users) or the command prompt (for Windows and Linux
users).
Change the current working directory to your local project.
Initialize the local directory as a Git repository.
git init
#Add the files in your new local repository. This stages them for the first commit.
git add
# Adds the files in the local repository and stages them for commit. To unstage a file, use 'git reset HEAD YOUR-FILE'. Commit the files that you've staged in your local repository.
git commit -m 'First commit'
#Commits the tracked changes and prepares them to be pushed to a remote repository. To remove this commit and modify the file, use 'git reset --soft HEAD~1' and commit and add the file again.
At the top of your GitHub repository's Quick Setup page, click to copy the remote repository URL. At the top of your GitHub repository's Quick Setup
page, click to copy the remote repository URL.
In the Command prompt, add the URL for the remote repository where your local repository will be pushed.
$ git remote add origin remote repository URL
# Sets the new remote git remote -v
# Verifies the new remote URL Note: GitHub for Windows users should use the command git remote set-url origin instead of git remote add origin here. Push the changes in your local repository to GitHub.
$ git push origin master
# Pushes the changes in your local repository up to the remote repository you specified as the origin.
Source attribution: Adding an existing project to GitHub using the command line
I assume you are on a Windows system like me and have Git installed. You can either run these commands by simple command prompt in the project directory or you can also use Git Bash.
Step 1:
Create a repository in Git manually. Give it whatever name you seem fit.
Step 2:
Come to your local project directory. If you want to publish your code to this new repository you just created, make sure that in the projects root directory there is no folder name .git. If there is, delete it.
Run command git init.
Step 3:
Run command
git add .
Step 4:
Run command
git commit -m YourCommitName
Step 5:
Run command
git remote add YourRepositoryName https://github.com/YourUserName/YourRepositoryName.git
Step 6:
Run Command
git push --set-upstream YourRepositoryName master --force
Please note that I am using the latest version of Git at the time of writing. Also note that I did not specify any particular branch to push the code into so it went to master. In step 6 the Git will ask you to authorize the command by asking you to enter username and password in a popup window.
Open Git Bash.
Change the current working directory to your local project.
Initialize the local directory as a Git repository: $ git init
Add the files in your new local repository. This stages them for the first commit: $ git add .
Commit the files that you've staged in your local repository: $ git commit -m "First commit"
At the top of your GitHub repository's Quick Setup page, click to copy the remote repository URL.
In the Command prompt, add the URL for the remote repository where your local repository will be pushed : $ git remote add origin remote repository URL
Push the changes in your local repository to GitHub: $ git push origin master
First you have to create an account on GitHub
Then create a new project - name that project as you want and then your project URL is shown
Now copy the URL
Then open a Command Prompt and go to the directory or folder which you want to upload using cmd
Then type the following commands
git init
git add .
git commit -m "initial commit"
git remote add origin PASTE URL
git push -u origin master
Now check your GitHub account. The repository is successfully uploaded.
For complete guidance, you can watch this video.
It took me like 1-2 hours to realize that I'm supposed to create the repository at GitHub before trying to push my local files to GitHub (or whatever, Git service you're using).
After trying to push, errors were like:
remote: Repository not found.
fatal: repository 'https://github.com/username/project.git/' not found
I feel like an idiot, but I really would like to emphasize this for beginners like me. I just thought that my repository will be created automatically during the first push. I was so wrong.
You can see your remotes with this command:
git remote -v
Steps to upload project to Git:
Step 1 - open cmd and change the current working directory to your project location.
Step 2 - Initialize your project directory as a Git repository.
git init
Step 3 - Add files in your local repository.
add .
Step 4 - Commit the files that you've staged in your local repository.
git commit -m "First commit"
Step 5 - Copy the remote repository URL.
Step 6 - Add the remote repository URL as origin in your local location.
git add origin copied_remote_repository_url
Step 7 - Confirm your origin is updated or not.
git remote show origin
Step 8 - Push the changed to your GitHub repository
git push origin master.
I think the easiest thing for you to do would be to install the Git plugin for Eclipse. It works more or less the same as the Eclipse CVS and SVN plugins.
Make sure that Git is installed on your system. I'm explaining the process using windows OS [Although it shouldn't be OS dependent job]
Here is how I did:
Open the cmd (you can do with git bash as well if you've installed git bash).
Go to your project directory (where your project is located, it's essentially changing to directory either usiing cd path or through manual folder navigation).
Now type git init. This will initialize an empty repository if it is first time and Enter.
For example: git init
Now type git add <filename>(if specific file) or git add <filename1> <filename2> <filenameN> (if specific but more than one files) or git add . (if you want to add all files) and enter.
Now type git commit -m "commit message goes here" and enter.
(in case if you need to check the status you can do by typing git status) and enter.
Now type git remote add origin git_repository_url
(check git remote -v go check remote repository) and Enter.
Now it's turn to push it to the remote repository [essentially taking all the changes from local git to cloud(github) ...git push origin master and enter
(if you get error you push it forcefully by typing ...git push -f origin master and enter.
NOTE : master is the name of your master branch. If you've multiple branches, make sure that you select the name of the branch accordingly.
Now you're done with adding it to your remote repository from local computer. Refresh it and it will be there in your created repository's selected branch.
Probably the most useful thing you could do is to peruse the online book Pro Git. It's really a pretty decent read and gives you the conceptual context with which to execute things properly.
Follow the instructions from RishiKesh Pathak. You can even short the push command by inserting this command line one time only:
git config --global push.default simple
So next time instead of using git push origin master you just need:
git push
See details here.
Download Sourcetree.
It is available for Windows 7 (and later) and Mac, and it is highly recommended to upload files on GitHub via the interactive UI.
The best way to use Git is to actually start Gitting. Try out this website which makes you go step by step on what are the essential ways for performing functions on command line for pushing a project on GitHub.
This is called try.github.io or you could also take up a course on Codecademy.
I did as follows;
git init
git add .
git commit -m "Your_message"
git remote add origin #your_git_repository
git push -u origin master
Of course you have to install Git.
We need Git Bash
In the Git Bash Command Section:
ls
It will show your default location.
CD "C:\Users\user\Desktop\HTML"
We need to assign the project path.
git init
It will initialize the empty Git repository in C:\Users\user\Desktop\HTML
ls
It will list all file names.
git remote add origin https://github.com/repository/test.git
It is your https://github.com/repository/test.git is your repository path
git remote -v
To check whether we have fetch or push permission or not
git add .
If you use . then it means whatever we have in the particular folder publish all.
git commit -m "First time"
git push -u origin master
Upload a project from Visual Studio Code to GitHub
To upload your project in GitHub using Visual Studio Code, follow the following steps.
Open the Visual Studio Code. if you don't have the VSCode download: Download Visual Studio Code
In VSCode go to File-->Open Folder..
Go to Terminal-->New Terminal
Execute the following commands one by one after one another in order
git init
git add .
git commit -m "First Commit"
git remote add origin https://github.com/yourusername/your-repo-name.git
git push origin master
Note: in the above command git remote add origin https://github.com/yourusername/your-repo-name.git please change the bold sections with your GitHub account name and your repository name.
You need an SSH connection and GitHub init into your project. I will explain under Linux machine.
Let's start with some easy stuff: navigate into your project in the terminal, and use:
git init
git add .
git commit
Now let's add SSH into your machine:
use
ssh-keygen -t rsa -C "your_email#example.com"
Copy the public key, and then add it to your GitHub repository:
Deploy keys -> add one
Back to your machine project, now launch:
git push origin master
if there is an error, configure your .github/config file by
nano .github/config
And change the URL to the SSH one by:
url = git#github.com:username/repo....
And that's it.
Try using Git Bash to push your code/make changes instead of uploading files directly on GitHub (it is less prone to errors and is quite comfortable at times - takes less time as well!). For doing so, you may follow the below given steps:
Download and install the latest version of Git Bash from here.
Right-click on any desired location on your system.
Click “Git Bash Here”.
git config --global user.name “your name”
git config --global user.email “your email”
Go back to your GitHub account – open your project – click on “clone” – copy HTTPS link.
git clone PASTE HTTPS LINK.
A clone of your GitHub project will be created on your computer location.
Open the folder and paste your content.
Make sure content is not empty.
Right-click inside the cloned folder where you have pasted your content.
Click “Git Bash Here” again.
You will find (master) appearing after your location address.
git add .
Try git status to check if all your changes are marked in green.
git commit --m “Some message”
git push origin master
You just need to know few command im cmd to push or pull any directory to/from github.
Command to push/upload any project or code to the git hub.
First reach to the working directory or project directory which you need to upload.
to check the correct working directory
ls
to initialize the git in the directory
git init
to the check that git init worked or not
ls -a //this command shows hidden files
Using above command you will find file added in you directory.
./ ../ .git/
the above is not a command you can skip it.
Now add the files of working directory to commit
git add .
then use commit command and name that commit for reference
git commit -m "Commit Name"
Before final step you need to go to the github website and create a new repository and copy the url of the repository
git remote add main https://github.com/username/repositoryName.git
now command to upload the directory
git push -u main
Note: the name "main" is the name that can be change as per user
For uploading a new project into Git (first you need to have the local code base of the project and the Git repository where you will be uploading project. In Git, you need to have your credentials).
List item
Open Git Bash
Go to the directory where you have the code base (project location)
cd to project location
cd ////**
Then here you need to execute Git commands.
git init
Press Enter then you will see something like this below.
The initialized empty Git repository in ://****/***/.git/, so git init will initialize the empty Git repository at local
git add .
Press Enter
The above command will add all the directories, subdirectories, files, etc.
You will see something like this:
warning: LF will be replaced by CRLF in **************.
The file will have its original line endings in your working directory.
git commit -m "first commit"
Press Enter. -m provided option for adding comment.
It will commit the code to the stage environment.
You will see some thing like this:
[master (root-commit) 34a28f6] adding ********
warning: LF will be replaced by CRLF in c*******.
The file will have its original line endings in your working directory.
27 files changed, 3724 insertions(+)
create mode 100644 *****
create mode 100644 *****
create mode 100644 *****
git remote add origin
http://username#git:repopath.git
Press Enter. This will add to the repository.
git push -u origin master
Press Enter.
This will upload all from local to repository in this step you need to enter password for the repository where you will be uploading the code.
You will see some thing like this below:
Counting objects: 33, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (32/32), done.
Writing objects: 100% (33/33), 20.10 KiB | 0 bytes/s, done.
Total 33 (delta 14), reused 0 (delta 0)
To http://username#git:repolocation.git \
[new branch] master -> master
Branch master set up to track remote branch master from origin.

How do i install rails application from github

Hi i have my application source code on github, now i want to upload it to my server. Should i first run rails new blog and then do a git init and git pull? Or do i have to create a folder manually, do a git pull to it and no need for rails new blog command?
first you want to git clone that repo from git hub
git clone blaa#github.com/blaa
once you get a folder created, go there and try doing
bundle
once that's done and once your dependencies are resolved, you can start the server
rails server

Heroku -- Push new content to a heroku app created from a different machine

Our team is working on an app. We have a SVN based app. We also pushed the app to heroku. The other day the app was pushed by one member of the team, and after a couple of days of work and making some updations other member wants to push his data on heroku in the same repo from another machine. How can this be done?
Please Help.
Thanks in Advance.
You need to use Git to push applications to Heroku. If your source control of choice is Subversion, then you can use git-svn to deal with a Subversion repository using Git, including pushing to Heroku.
You need to add a git remote to the Heroku Git URL. You can find this URL in your Heroku account at heroku.com.
# stuff about setting up git-svn
$ git remote add heroku #{heroku_git_url}
$ git push heroku master
As another commenter mentioned, you will also need to manage SSH keys. The user doing the pushing will need to have an SSH private key (you can look up ssh-keygen) and will need to have the SSH public key uploaded to Heroku (heroku ssh subcommand).
So if your app is deployed and you already have a working copy. And you need to push changes.
You only want the repo with no content.
git clone --no-checkout git#heroku.com:<your-app-name>
That will clone the repo into a directory named your-app-name, and in that directory will be the repo you want. Move that .git file next to your .svn file.
mv <your-app-name>/.git ~/Code/<your-working-copy>
rm -rf <you-app-name>
You can rename the origin remote to heroku if you want. Otherwise just
git commit -am "Deploying v1.2"
git push

Resources