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

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.

Related

Trying to pull updates from remote repo is failling for recently created branch

At work we have to use Bitbucket and to create the new branches we have to use the webpage.
When I do this and try to update my local repo using git pull I can see all the code, commits and even branches created by other users are pulled from remote except for the branch I recently created.
Then I have to keep trying git pull and see the message Already up to date. for 15 or 20 minutes until suddenly the branch is updated.
I was using https to clone the repos and I realized that using SSH started to avoid this issue, but a few weeks later I'm starting to see this issue again with SSH as well.
I'm assuming the issue is related to Bitbucket but I haven't found any info.
Is there a way to avoid this? or maybe a way to force the update?
Try first a git fetch, or even a git ls-remote
The goal for the ls-remote command is to check (right after creating/pushing a new branch) if:
said new branch is immediately listed in the remote tracking branches listed by ls-remote
the associated HEAD SHA1 for that branch is the right commit (the latest pushed on that branch)

Using git pull properly

I am new to git so please bear with me. I have a rails application on my local machine that I am experimenting with and pushing to the master branch periodically. It works at the moment, but I have fallen behind, and now I am many commits behind the master.
$ git branch
* master
$ git status
On branch master
Your branch is behind 'origin/master' by 27 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
nothing to commit, working tree clean
However, when I use git pull and then start rails, my application breaks with a precompiler error. So I am forced to use git --reset to go back to the local commit before I used git pull.
What is the right way to get around this issue and merge with the latest changes on the master branch? Would one use git --rebase in this case?
Try
git stash
git pull origin master
And once it updates, git stash apply to reapply your local changes
Since nobody has stated this clearly yet: You ask
What is the right way to get around this issue and merge with the latest changes on the master branch?
When you do git pull that does merge the remote changes into your current branch. Whether you would choose to do a rebase instead of a merge (per your other question) is a separate issue, but the default behavior is to combine the two sets of changes (local and remote).
More precisely, by default git pull does a fetch followed by a merge. The exact merge operation depends on configuration and on command-line options, but in a typical configuration where origin/master is upstream of master, saying
git pull
will merge origin/master into master.
So why the errors?
One possibility is that there were merge conflicts. If that happens, git will tell you. If you say git status in this condition, it will tell you that there's a merge in progress and it will indicate which paths (files) need conflict resolution.
Another possibility is that the changes don't conflict (in that they don't affect the same region of the same file) but still don't work properly together. That you would simply have to debug.

How to fetch branches and commits of Git Repo using LibGit2Sharp from network path without a local repository?

Using LibGit2Sharp, how can I fetch the list of all Remote Branches given the repo url ?
I do not have a clone of the repo on the local disk. What's the simplest way to get the list of Branches and once I get the list of branches, I'd like to get the list of Commit Id's in a branch of my choice.
I do see a way to do all this if I have a Git Repo cloned on my local disk but, I don't want to clone it for obtaining this info.
Using LibGit2Sharp, how can I fetch the list of all Remote Branches given the repo url ?
I do not have a clone of the repo on the local disk. What's the simplest way to get the list of Branches
Through LibGit2Sharp, one can read information about the references (mostly branches and tags) of a remote repository, without cloning it. This will retrieve the name of those references and the sha of the commit each one points to.
This can be done through the IEnumerable<Reference> ListRemoteReferences(string url) static method. This is the equivalent of the git ls-remote CLI command.
once I get the list of branches, I'd like to get the list of Commit Id's in a branch of my choice.
Unfortunately, ListRemoteReferences() will only return the tip of each branch. Would you need to enumerate the other commits referenced by this branch, only using LibGit2Sharp, you'll have to locally clone the remote repository.
As an alternative, rather than cloning, once you've got the SHAs of the tips, you could leverage the Commit GitHub API and for each commit, retrieve its parent(s), reapplying recursively the API invocation for each of them. Note that this last option will be far less performant (network I/O, API rate limitting, ...).

Need some basic github help

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.

git pull from a github repository fork gives conflicts

I have forked rails git://github.com/rails/rails.git at github. My forked repository is at git://github.com/waseem/rails.git. I want to test out some patches submitted by other users to rails mainline. Lets say I want to test out code in migration_status branch at git://github.com/joelmoss/rails.git.
Lets say I
master $ git remote add joelmoss git://github.com/joelmoss/rails.git. and
master $ git remote add mainline git://github.com/rails/rails.git.
I have been pulling from rails mainline into my master.
master $ git pull mainline master
According to http://guides.rubyonrails.org/contributing_to_ruby_on_rails.html#testing-patches I should create a local topic branch and pull in changes from joelmoss/migration_status. So I,
master $ git checkout -b migration_status Create a local topic branch.
And when I do:
migration_status $ git pull joelmoss migration_status
I get a large number of conflicts. I also tried migration_status $ git pull --rebase joelmoss migration_status but I still get conflicts.
In the case of pull --rebase, I think (correct if wrong), git is trying to apply my local changes on top of changes fetched from joelmoss/migration_status. Ideally it should do the opposite. To consider this option, I did following.
master $ git fetch joelmoss
master $ git checkout -b joel_migration_status joelmoss/migration_status and
joel_migration_status $ git rebase master it still gave me lots of conflicts.
How do I pull in patches submitted to one of my local topic branches w/o getting conflicts? I can not resolve those conflicts as I do not know much about what code to keep what not to.
In this case, it looks like joelmoss/migration_status is based off of 3.1.0, which split from mainline/master back in May. So if you merge you're trying to reconcile 4 months worth of development by everyone, in branches that appear to never have been intended to merge.
What you want to do is base your local changes on 3.1 as well. That doesn't guarantee to remove all conflicts, but at least it should be ones you are aware of because it's code you changed directly.
git checkout -b master-3-1 master
git rebase --onto joelmoss/migration_status mainline/master master-3-1

Resources