Need some basic github help - ruby-on-rails

I am trying to learn github to deploy a webpage. Here are the steps I am taking:
git checkout master
git pull origin master
git checkout –b my-awesome-branch
Do some work, do a git status to check on everything, everything is ok.
git add .
git commit –m "awesome message here"
git push origin my-awesome-branch
git checkout integration
git merge my-awesome-branch
git push origin integration
cap development deploy
this will push a file to the dev server we have so people can look at it - this worked fine for me you won't be able to see the link but it generates something like this:
http://dev.mywebsite.com/events/email/welcome
Let's go live (pretending there are no further changes)
git checkout master
git merge my-awesome-branch
git push origin master
cap production deploy
In theory, the file should push to the live website (which would be http://mywebsite.com/events/email/welcome) but that webpage is not created when i cap production deploy.
Another developer more familiar with this system says :
It looks like you forked "my party events" repo and have pushed the
master there. You'll want to push master to the upstream remote (the
main "my party events", or my_events repo.)
I don't follow this step. Can anyone follow this logic? If so, do you have a suggestion for me on what i may be doing wrong? Any help is appreciated.

If you have a forked branch on Github, that means you have a copy of the entire git repo under your name. Check your Github account to verify this.
To do this, go to https://github.com/your-github-user-name-here. On the left side, look for "my-party-events" (assuming that's the repo name). Underneath it, look for "forked from xyz/my-party-events".
If you don't see 'forked from ...', then you're the original owner of that repo. This shouldn't be the case.
If you do see 'forked from ...', then you have a copy under your name (that's what a fork is). Any changes you make to a fork don't affect the original repo.
If you're with me up to here, there's 2 ways you can go.
Via Git (Recommended)
Whenever you did a git pull or git push earlier, you were specifying origin, which is a human-readable name for a repo that you set up earlier. The repo address actually looks like this
git#github.com:your-user-name/project-name.git
As you can see, referring to it by a nickname like 'origin' is way easier to remember.
Assuming you have write access to the main project repo, you can just add another repo to your config. Make sure you have write access before attempting this, otherwise you're just wasting your time. Ask your coworker if you're not sure.
Lets say you wanted to nickname the repo as 'production', you would do this
git remote add production git#github.com:PROJECT_OWNER/project-name.git
The git repo address looks almost identical to your fork repo. It differs only by username. On the front page of all Github projects, the repo address is in a text field. It's next to the "SSH | HTTPS | Git Read-only" buttons. Get the address from there, replace it in the command above, and finally, do this in your command line
git push production master
From now on, you can just git push production master, which is pretty simple. If you don't have write access, then you'll have to submit changes via pull requests.
Through the Website
You can submit a pull request to the repo you forked from. A pull request asks the original repo admin to include changes you've made on your fork.
To submit a pull request, click on your project fork from your projects page. Look for the 'Pull Request' icon near the top right. That should take you to a page where you can choose the target and source branches.

Related

How to get Bitbucket/Git URL for a specific branch?

I use bitbucket but I need to pull a specific branch using the git url.
My git url look like:
https://bitbucket.com/scm/<project_name>/<repo_name>.git
I need to pull specific branch though so I tried:
https://bitbucket.com/<username>/scm/<project_name>/<repo_name>/branch/<branch_name>
https://bitbucket.com/<project_name>/<repo_name>/branch/<branch_name>
https://bitbucket.com/scm/<project_name>/<repo_name>/branch/<branch_name>
https://bitbucket.com/scm/<project_name>/<repo_name>.git#<branch_name>
I keep getting errors like 501 or not found
The goal is to connect my repository to Informatica https://docs.informatica.com/data-integration/powercenter/10-4-0/application-service-guide/model-repository-service/version-control-for-the-model-repository-service/configure-and-synchronize-a-model-repository-after-changing-vers.html
I'm not 100% sure I understand what you are trying to do.
If you have already cloned your repo, you can pull a specific branch using the url instead of the name of your remote.
# You normally pull with this command:
git pull origin my_branch
# You can pull using the URL instead:
git pull bitbucket.com/scm/<project_name>/<repo_name>.git my_branch
If you have not yet cloned your repo, you can clone a specific branch:
git clone --branch my_branch bitbucket.com/scm/<project_name>/<repo_name>.git
I need to pull specific branch though so I tried:
Those all seem like reasonable ways to do it for http urls, Git uses a way that doesn't depend on any specific server's url format
git remote add somename u://r/l -t branch
and you can repeat the -t branch option as many times as there are branches you'd like to track, or just let it default to all branches.
If you don't want tags, add --no-tags. I usually don't for sideband repos like this, I count it as a minor wart, probably too late or anyway not worth it to fix, that git remote add doesn't default to this for any remote not named origin.
Then
git fetch somename
brings the tracking refs up to date.

How to push changes from Bitbucket to Heroku

I'm new to programming, learnt languages but this part I have no clue.
I'm working on a app that is on bitbucket and on Heroku cloud.
I am not exactly very clear how the bibucket repository interacts with Heroku and also my local offline commandprompt+sublimetext+PG database.
So what I'm doing is i have made some changes physically on Bitbucket (manually on their website) based on the changes Ive made and viewed (offline on localhost 3000) and wanted to push it to Heroku to have the changes online. There does not seem to be any buttons on bitbucket for that purposes and I guess I have to do it through the command prompt.
In that case how do I make those changes (command lines) and update the sublime+PG on the local server? I seen a few codes on git and suspect those are it (like git push -v) which lists the repositories but I don't wish to test and end up screwing the codes. Please advise if there are easier to do any of the above.
Note that I want the changes to be on Heroku because of this error.
Rails 4 Relationship Issue extended
Also what the difference between pulling and pushing changes? I'm reading the git definitions but it isn't saying much. Just that pull is pulling data from other repository to I'm not sure where. Push is to update remote refs with associated objects.
Many thanks!
Because you're new, let me explain what you need:
Heroku uses an amazing deployment process which based on the git scm
system. This means that you just need to "push" your git
respository to Heroku in order for it to deploy your latest revision
of code
The problem you cited is you're trying to push from bitbucket
directly. Bitbucket / github are essentially just cloud
repositories where you can store your code, and is not where Heroku
can "read" your files from
To get this working, as you've stated in your comments, you need to push from your computer. This is achieved by creating a remote repository for Heroku, and then pushing to that, like this:
$ git remote add heroku git#heroku.com:yourherokuapp.git
$ git add .
$ git commit -a -m "Latest Commit"
$ git push heroku master

Working with Git branches

I have a Rails app deployed on Heroku and I have a git repo that I'm currently working on with uncommitted code changes. In the meantime, I need to make changes to the source on Heroku independently of the local repo. Can I do the following:
Clone the Heroku git repo on the same development machine with a different app name though with the same account
Make changes to the new local repo
Commit those changes to the new local repo
Push those changes to the Heroku repo
Resume working on my original local repo
Will this approach work?
Yep, that workflow would work, or stash them - and don't forget if you do make a clone of the heroku repo you'll have made changes to a different clone of the repo and you'll need to make those changes in your original local repo.
In future I'd suggest that you assume that your 'master' branch is what's live on Heroku and branch of that to work in - you can even push this branch into a new app for testing purposes. This way bug fixes can be performed on your local master branch (or another branch and merged into master) and pushed to heroku and then when you've finished your new work you merge the branch back into master and deploy that to your live environment. I wrote a blog article on the subject a while back, here
I haven't used heroku but if I wanted to make changes to a deployed application while I had unsaved changes in my sandbox, I would do one of the following.
stash my local changes, cut a branch from the point where I want to make a fix, make it, deploy it, switch back to my original branch and pop from the stash.
Commit my unsaved changes (into the current branch - say work), cut a branch from the point where I want to make a fix, make my fix, deploy it, switch back to work, reset my HEAD to before my "temporary" commit and resume work.
Unless you're using git in an unconventional fashion, there's no need to make another clone.
If you clone the heroku repository to a separate directory, made changes and push it from there, then there is a possibility of conflicts later down the road.
If its only the issue with the uncommitted changes then certainly you can stash them using "git stash" and later retrieve it using "git stash pop".
My work-cycle: I always keep a master branch with the #1 rule "always push to Heroku after committing something to master". If I code on something that I do not want to deploy immediately, I have to branch.
I know this works not for all use cases, but having always a branch that is identical to the app that is productive on Heroku makes me sleep better ;)

Backing up work on a branch using heroku, rails and git

Rails/Heroku/Git newbie - here is my question. I have an app deployed with Heroku and am using the git repository hosted there as the only remote copy of my local work. I start making changes locally on a new branch and want to make this branch available on Heroku so that I can continue work on it from another computer. Heroku ignores branches other than master and I don't want to merge my changes yet (or push them as master). Is there a way to store/access my new branch via my Heroku git repository, or is it better to have another remote git repository for my work in progress.
Thanks!
You can push a local branch to the remote git server with:
git push origin branch_name
That way, you can pull it down again elsewhere with:
git checkout -b branch_name origin/branch_name
http://gitready.com/beginner/2009/02/02/push-and-delete-branches.html
http://gitready.com/intermediate/2009/01/09/checkout-remote-tracked-branch.html
I would go with a separate git repository as suggested - github.com or similar. Store your code there and deploy to Heroku's master repo - Heroku is a hosting platform afterall not a home for your repos.
ALTERNATIVELY Make use of dropbox and create your local workspace in a dropbox folder that is synced across multiple computers - I employ this method as well as git - plus you get the advantage that Dropbox is versioned so if you delete/change a file that you haven't committed yet you can get it back.

Is there a way I can view changes committed to my local GitHub branch without having to push it to the master branch?

I'm still figuring GitHub and Heroku out, so please bear with me. :)
I've a web app on, say, xyz.com. What I am doing now is to make some code/UI changes on some files, commit those files, push them to the master branch, and then refreshing the url to see these changes.
I think this is obviously the wrong approach, but I don't know of how else to test changes done to my code without having to push them on to the master branch. How could I do so?
I don't quite understand the situation in the full version of your question (see my comment and, as icc asks, why can't you test locally?), but to answer the question in the title, you can see the differences between your master and the version on GitHub by running:
git fetch github
git diff github/master master
(That's assuming that the remote that refers to your GitHub repository is called github - it might well be origin in your case. You can see all your remotes with git remote -v.)
To explain that a little further, when you run git fetch github, git will update all your so-called "remote-tracking branches" - in most cases those are the ones that look like origin/whatever, github/experiment, etc. Those are like a cache of the state of those branches, and they're only updated when you run git fetch or successfully git push to that branch on the remote repository. So, once you've done this to make sure that github/master is a recent snapshot of that branch on GitHub, you can happily compare it with your local master branch using git diff.
First: You don't push to the master branch, you push to a remote repo. You should probably read up on your git.
Second: This is not a good workflow, first you should commit your changes and then test them locally. When you are done testing you are ready to push your commits to a remote repo.

Resources