How to clone TFS to GitHub with history using Git-TFS? - github

I'm trying to clone a GIT repository in TFS using git-tfs using TFS 2012
git tfs clone http://sourcecontrol.oldcompanyname.local:8080/tfs/foo $/companyname/myrepository . --b=all --resumable
Gives me:
error: the path $/companyname/myrepository you want to clone doesn't exist!
I have an empty repository called /companyname/myrepository in my github account
(the urls and names are genericized for the public post)

Git TFS is for converting TFVC repositories to local Git repositories. It has nothing to do with GitHub. Once you have a local repo, you can add a GitHub remote and push it there.
The clone URL should be the path to your TFS instance, stopping at the project collection. http://companyname.local:8080/tfs/DefaultCollection.
The next part is the path to a folder in the TFVC repository. If you have a team project named Foo and you want to clone the Main branch, you'd specify $/Foo/Main.

Related

Importing GitHub repository into a specific folder

I have a GitHub repository that I've created by copying content of a specific folder.
Now I have installed GitHub Desktop and I would like to directly connect this directory to my GitHub repository instead of re-downloading and creating a copy.
How can I do this?
Before switching to GitHub Desktop, you should prepare the environment for that folder, in order to be linked to the remote repository:
cd /local/path/to/folder
git init .
git remote add origin https://github.com/<me>/<myRepo>
git fetch
git switch -m master
Then you can open GitHub Desktop and add a local repository (the folder you just configured)

Is it possible to push to a new remote on VSTS git?

Is it possible to create a new VSTS Git remote repository from a Git client?
Right now, I have to go to visualstudio.com first to create the new repository before adding and pushing it from PC git, using the url created in VSTS.
I tried the following:
git remote add brandnew xx.visualstudio.com/PROJECT/_git/qqq
git push brandnew --all
where I am the owner of xx.visualstudio.com and PROJECT is an existing project, but qqq does not exist.
The above gives me:
remote: TF401019: The Git repository with name or identifier qqq does not exist or you do not have permissions for the operation you are attempting.
fatal: repository 'https://xx.visualstudio.com/PROJECT/_git/qqq/' not found
Yes, it's possible.
Even you can not create a VSTS git repo by git command line by default, but you can achieve it via git hooks.
And for the reason why you can create and publish new VSTS git repo via VS, it that VS will create the new VSTS git repo by API not by git commands.
So if you want achieve this feature in git command line, you can use pre-push hook for assistance. Functions need to achieve in pre-push hook as below:
Detect if the remote repo https://xx.visualstudio.com/PROJECT/_git/qqq exist or not.
If the repo is not exist in VSTS, then create by REST API.

How to merge changes from Github to TFS

So I'm working semi-remotely on a project for a company with a small team. We have only a single VPN-enabled laptop to access their TFS which remains in a single secure office. We want to use Github to collaborate and get all our work onto the company Laptop, and then transfer that work to the company's TFS.
However I can't find a way to merge changes from the Github repo on the laptop to the TFS repo on the laptop without just brute-force ctrl-c/ctrl-v the directory which does not seem like the ideal solution.
Here is the file situation on the laptop with an arrow indicating the desired change transfer
Is there any clean way to do this?
You can merge changes from github to TFS repo by below steps:
Move files into subfolder in local github repo
Assume DEV is the subfolder for TFS git repo root directory, you can create the same folder DEV in github repo, and move files in the subfolder:
# In local github repo
mkdir DEV
mv * DEV
git add .
git commit -m 'move files into DEV folder'
Add local github repo as a remote for local TFS repo
Assume the local github repo in C:\GitHub\My_Workflow_Dashboard,then you can add the local repo as the remote for your local TFS git repo:
git remote add github C:/GitHub/My_Workflow_Dashboard -f
Merge changes from github into TFS repo
Then you can merge the changes from github (such as master branch) to TFS by below commands:
git merge github/master --allow-unrelated-histories
git push
Or you can add -X theirs option (git merge github/master --allow-unrelated-histories -X theirs) to auto resolve merge conflicts by keeping the version from github repo.

Cloning a github repo into an existing project?

I have a project in Eclipse that I want to put on github, so I went to github and created the repos for them, but I want to clone them right into the folder where the files are stored in my eclipse workspace. How can I do this?
EDIT: When I try it, the github app says it can't clone because the folder isn't empty.
EDIT 2: Will this work? Changing the name in eclipse to rename the project folder, then cloning the repo to the name I want, in the workspace, then renaming the eclipse project so they merge and I can commit the new files.
GitHub has a guide explaining how to put an existing project on GitHub.
You should not clone the repository, but add the GitHub repository as a remote to a local repository you create yourself.
Go to your project folder and initialize a local repository with git init
Add and commit all your project files to the local repository. (e.g. git add . and git commit -m "message")
Add the GitHub repository as a remote. git remote add origin *github repository URL* (Verify with git remote -v)
Push your project to GitHub with git push origin master.
If you already have committed files to the GitHub repository, it is still possible.
Initialize your local repository.
Add GitHub as the remote.
Pull from GitHub.
Add and commit your project.
Push you project to GitHub
First add the remote as follows
git remote add origin <GIT URL>
Then simply do the following (MAke sure to commit any of your local files)
git pull --allow-unrelated-histories

How to migrate a private Bitbucket repository to a public Github repository

How can I migrate a private Bitbucket repository to a public Github repository?
Make a "bare" clone of the repository (i.e. a full copy of the data, but without a working directory for editing files) using the external clone URL. This ensures a clean, fresh export of all the old data.
Push the local cloned repository to GitHub using the "mirror" option, which ensures that all references (i.e. branches, tags, etc.) are copied to the imported repository.
Here are all the commands:
git clone --bare https://bitbucket.com/user/repo.git
cd repo.git
git push --mirror https://github.com/ghuser/repo.git