How to locally update repository from github - github

If I cloned a github repository with the follwoing command:
git clone - git://github.com/user/project.git
And then the developer commits further changes (to the main branch) how can I get the latest changes locally?

git pull
Also check out this resoruce for a visual representation of the git commands.

A git pull will retrieve the changes from the main branch to your local repository

Related

Azure Devops Migrate from TFVC to Git

I try to migrate from tfvc to git like the picture1.
but nothing comes into git repository like the picture2.
We can reproduce this issue and we have reported this issue, you could refer to this ticket to get the latest news.
As a workaround, we could migrate the TFVC repo to Git via git cmd.
let’s follow the migration guide and execute the clone command:
git tfs clone {TFVC repo URL}
Get all branches:
git tfs branch –init --all
For each branch, run these commands:
git checkout branch
git log -1
git tfs pull -c=changesetNumber
Create a new repo in the azure devops and get the repo URL. Then setup the git repository upstream:
git remote add origin {New repo URL}
Finally you push all your local changes to the Remote.
git push origin -u -all
We could refer to MIGRATING FROM TFVC TO GIT and Migrate From TFVC To Git for more details.
Update1
According to the latest news: A fix for this issue has been prepared. We’ll update you when it’s available.

How to open a pull request on github for an improvement in a bitbucket fork?

I cloned a github repository into our Bitbucket account. Similar to https://gist.github.com/sangeeths/9467061.
I fixed a bug in my repository located in bitbucket. I'd like to open a pull request on the original github repository that fixes the bug.
If my fork were located on github, I would simply follow these instructions, but since my fork is on bitbucket, I don't know where to start.
How can I open a pull request from my bitbucket repo to the original github repo ?
You can:
clone the original GitHub repository to a different folder
add your local BitBucket repo as a remote
fetch your fix branch (make sure you fix is done in its own branch, not master)
create a PR using the cli/cli GitHub command line interface gh pr create
That is:
git clone https://github.com/original/repo
cd repo
git remote add bb ../yourLocalBitbucket/repo
git fetch bb
git checkout bb/fix
gh pr create
The gh pr create command will do the work for you:
When the current branch isn’t fully pushed to a git remote, a prompt will ask where to push the branch and offer an option to fork the base repository.

Is it possible to merge changes from old repository to a duplicated repository?

In GitHub, Is it possible to merge changes from old repository to a duplicated repository? If it is possible, what are the steps involved?
These are the steps I'd follow to duplicate a repository.
Yes, but you should do it local.
So
Clone you repo locally. git clone <url>
Added a second remote for the old repository git remote add old <url>
Checkout a branch from your second remote and push it to the first.
E.g. something like this:
git fetch old
git checkout old/mybranch
git checkout -b newname
git push origin -u

Moving a particular branch from bitbucket repository to Github or Moving Bitbucket repository to Github without commit history

Is there any way we can move a particular branch from bitbucekt repository to Github repository?
Is there any way Bitbucket repository can be moved to Github without moving the commit history(without removing the git folder and re-initializing the git)
You can add multiple remotes to a repository with git remote add. Once a remote exists, you can push whatever you like to it.
In this case, you can push the branch named newbranch to a new GitHub-hosted remote by doing something like this:
git remote add github https://user#github.com/owner/repo
git push github newbranch
This will include all commits associated with that branch, because that's how Git works. (If you just want to give somebody a copy of the code that doesn't include any history, then you should use git archive instead.) It will not automatically update the GitHub version with changes made on Bitbucket or vice versa, though you can push updates manually or with a script.

Fork from a branch in github

Is there a way to fork from a specific branch on GitHub? … For example, moodle has many branches (1.9, 2.0 … and so on). Can a clone be performed of just branch 1.9 and not the master branch always? Is it possible to clone a specific branch onto my PC?
I don’t know a native way yet, but you can do it following this recipe:
Fork the repository in question (called ‘upstream’) on the GitHub website to your workspace there.
Run the GitHub desktop application and clone the repository onto your PC.
Use the GitHub desktop application to open a shell in the repository. (The git commands are not available from the default PowerShell unless you configure that manually.)
Set the source repository as upstream:
git remote add upstream https://github.com/{user}/{source-repo}.git
Fetch the full upstream repository. (Right now, you only have a copy of its master branch.)
git fetch upstream
Make your file system copy the branch you want and give it any name:
git checkout upstream/{branch-in-question}
git checkout -b temporary
Publish your repo using the GitHub desktop application.
On the GitHub website, open your repository and click ‘settings’.
Change the “Default branch” to ‘temporary’. (Just change the drop-down menu, you don’t need to click the “Rename” button.)
Go back to your repository, go to the ‘branches’ tab, now you can delete the “master” branch.
Delete the master branch on your shell and make a new master branch:
git branch -d master
git branch master
git checkout master
git -d temporary
Once more, publish your repo using the GitHub desktop application.
On the GitHub website, open your repository and click ‘settings’.
Change the “Default branch” back to the (new) ‘master’ branch.
Go back to your repository, go to the ‘branches’ tab, now you can delete the “temporary” branch.
This should be what you were looking for. Perhaps GitHub will provide a more convenient way to do this in future (e.g., clicking “Fork” from a project’s branch results in exactly this behaviour).
Cloning means that you create a copy of the whole repository in your account including all branches and tags. However you are free to switch and track branches however you like.
No command line needed. Just create a new branch in your forked repository in GitHub. GitHub will ask you if you want to clone/mirror this new branch from the upstream repository. You can give any name to the new branch.
Yes, you can clone the single branch. For example, you have a branch named release1.0. If you would like to clone this branch into your pc then use the following line of code:
$ git clone git#bitbucket.org:git_username/git_repository_example -b release1.0 --single-branch
For those who don't like working with command-line. Here is a simple guide using the desktop client for GitHub:
Click the fork button of the repo on GitHub.com:
Make sure you have the desktop client installed
Click this button:
Clone the repo
In the desktop client, select the desired branch
Select the branch you'd like to work on and you're done
I'm posting here the method I've used.
Like the OP I wanted to only copy/fork one branch. But couldn't find an easy way.
in your repo create a new branch. It doesn't need to have the same name as the branch you want to fork
once created, verify that it is the selected branch, and click "Compare"
reverse the order of comparison (I have a userscript for that, see my profile if it's something you want to test).
the "base" repository must be yours, with the branch you've created
the "head" repository is the original, and the branch is the branch you want to fork
hit "create pull request" and continue until the PR is applied
That's it. You have the branch forked.
I'm using bitbucket but I'm sure this would work for GitHub as well.
Create a new repository
Checkout the branch using GitExtensions
Click Push to open the Push dialog
Set the destination URL to the new repository
Set the destination branch to "master"
Push
Your new repository will have the full history of the one branch only (not all branches like forking will have).
A fast, alternative approach is to create your own new repo.
Go to https://github.com/new and make a new repo. Do not initialize with README.
Scroll down to get your git remote
Then:
git remote rm origin
git config master.remote origin
git config master.merge refs/heads/master
// Run code from above image
git push --set-upstream origin yourbranchname
You will have a new repo with the original repo's code and a branch that can be made into a pull request.
SOLUTION:
For remote repository on GitHub and local repository
After fork all branches to your GitHub repository, you can delete Redundant branches in your GitHub repository.
And then you can only clone the branches you need to local.
Step One
Step Two
Only For local repository
git clone -b <branch name> --single-branch <repository>
If you want to further save your disk space, you can clone remote repository without history:
git clone -b <branch name> --depth 1 <repository>
notice: --depth implies --single-branch unless --no-single-branch is given.
https://git-scm.com/docs/git-clone
Switch to the branch you need in source repo
Click "Fork". You'll get forked master and the branch you're in.
I don't know how it works with more branches, but for my needs worked pretty well.