How to merge changes from Github to TFS - github

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.

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)

Jmeter integration with Git Hub ( How to push/Pull jmx,parameter files to Git)

Need to Save Jmeter JMX/data files to github from Jmeter. How to point jmeter datafiles/parameter files to GIT files. While running the test jmeter need to pull latest datafiles from GIT
I downloaded GitHub Desktop from here.
Link your GitHub account and then create or clone a repo.
Then any files edited within that directory will be recognised and can be pushed to GitHub, including jmx files.
Can also easily add files/folders/results/HTMLreports etc easily from your local machine.
You can upload an existing file to a GitHub repository using the command line.
Copy the JMX\data files you'd like to push to GitHub into the local directory that was cloned from the repository.
Run Git Bash.
Change the working directory to your local repository.
Add files to commit in your local repo:
git add test.jmx
Commit files to your local repo:
git commit -m 'Some comment text'
Push your files from local repo to GitHub
git push origin your-branch-name

local git repository with two remote git repositories

On my local git repo, I used to push it to two different remote repo, one on github and another on heroku. Now my local is stuck on heroku repo and I want to create a branch from github master branch. How can I change from heroku to github(origin)?
[thi is what my terminal looks like]
See here - you want to set your local branch to track a different remote: Make an existing Git branch track a remote branch?

On-premises GIT repository with Visual Studio Team Services Project

We have on-premises installed GIT. There we have our code repositories.
Is it possible to connect a repository from this on-premises instance to Visual studio team services project?
So they display under "Code" bar?
vsts
I need it hosted on premises, but see code changes/commits and other GIT stuff in VSTS project
No, it isn’t supported to display files or code of another repository under Code bar. You need to import that repository to the repository in VSTS. After that, you can push updates to VSTS repository if there are changes in your on-premises git repository.
You can't connect on premise GIT to VSTS. You may however use the VSTS rest APIs to push in code from your on premise GIT to VSTS.
Typically you will setup a hook/trigger on your on premise GIT repo in order to automate the replication process.
As others have said, you can have a "git hook", which is basically a git trigger to take action on some event. In this case, when code is pushed, to push it up to VSTS, but I assume you need to know the technical commands.
I had to do this the opposite way, and I did this quick and dirty. This pushes everything in one go, not each commit. This can also catch up a repo that is behind.
# Clone source repo (your local git repo)
git clone some_repo_path_goes_here
# I am skipping steps and assuming you are only syncing master branch.
# I have code to get all branches down before proceeding, but not posting it here.
# Assuming tags are on master branch..
# Get all tags
git fetch origin --tags
# Test to see if remote alias already exists
git ls-remote http://path_to_.visualstudio.com/org/project/_git/TargetRepoSameName
# Add a remote alias
git remote add any_name_123 http://path_to_.visualstudio.com/org/project/_git/TargetRepoSameName
# push local repo to 'any_name_123'
git push any_name_123 --all
# optional: delete all tags before attempting to push local tags
git push any_name_123 --delete `$(git tag -l)
# push local tags to remote repo
git push any_name_123 --tags
You can schedule this job if you would like. I have a PowerShell job to do this with a lot more functions to do pull down the branches.

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.