How to change remote for syncing in VS Code? - github

I used to fork a repo on GitHub and then clone my fork, and be in origin.
Recently I've been cloning the original repo and then using hub fork, and now my remote has my username instead of origin. (I understand why this is happening, that's not my question).
I can use git push my_username master in the command line. But I'd rather use the sync button/commands in VS Code. But that's trying to sync with the origin, which of course I don't have permission to push to.
How do I switch it to push to my fork? I actually got it to work once, but it was by a bunch of accidental clicking.

I believe you are looking for the repository settings. The link to them is located under the Team Explore Tab -> Settings -> Repository Settings. At the bottom of that area under remotes you can specify the remote origin for push and fetch.
UPDATE: The above is for VS 2015 GIT settings. This is different for VS Code. In the Source control area there is three dots (...), click on these to get to the more options including the remote origin. I don't have VS Code so I can't help you after that point. Hopefully the documentation will guide you further if you need help.
https://code.visualstudio.com/docs/editor/versioncontrol

Related

Used Github Desktop and now terminal not detecting changes

I used Github Desktop to perform a complex merge and now I've noticed that my terminal is not picking up any changes when I run:
git status
I need to first push the code up to origin using Github Desktop, then pull down in my terminal in order for the changes to take place.
Has anyone seen this before?
It appears that github desktop somehow made a clone of the repo in a new location which is why my terminal wasn't locating the file changes. The github desktop repo was located at: /Users/NAME/Documents/GitHub/repo-name. I'm sure this is something I screwed up during setup but figured I'd throw this out there in case it helps anyone!

Is it possible to source control using VS Team Services without using Visual Studio or other IDE?

There are similar questions to this but they mostly have some other purpose than mine, use different tools or end up not being that similar.
I've been searching for another way to source control Dynamics NAV development, as we've been using an in-house add-on called Object Control which merely controls changes to objects and produces .txt backups.
With those .txt backups we could do normal source control using Visual Studio Team Services, but we want to avoid the hassle of opening Visual Studio just to connect it all to Team Services everytime we make changes.
I know Microsoft has a set of REST APIs for retrieving information on repos and projects but i'm not sure how you can send information to the server (new changesets, files, creating projects, etc) without using an IDE.
I'm set on creating an application or interface to bridge the gap between the NAV development and Team Services but is there a way to use and communicate with Team Services on its own?
Yes, you can use the git command line to source control VSTS git repo. You can use git bash (download here).
Frequently commands as below:
git clone <URL of VSTS git repo> #clone a git repo of a VSTS project locally
git add filename #add the file in git repo
git commit –am 'message' #commit the changes with comment: message
git push #push current branch to remote (VSTS git repo)
More git commands, you can refer git book.
Power Tools. It integrates with windows shell and you can do everything w/o opening VS
DLLs that installed along with VS TFS can be used like any other libraries in your application. Or you could even use then in Nav RTC. I used this approach have some inconsistencies but in general it works smoothly. So you can sourcecontrol Nav from Nav itself.
Rest services since you mentioned them. I'm just not sure if they provide access to work items only or to source control as well. For you to explore.
If you chose Git for source control, you just need the command line to commit changes and push them to VSTS.
In VSTS go to Code -> Manage Repositories -> New repostiroy. Choose Git as the type and give it a name. On the top right of the new repository home screen you'll find a button "Clone", copy the URL for the next step.
On your machine install Git then open a command prompt and navigate to the folder with your source code and type
git init
git add .
git commit -m "Initial Commit"
git push --set-upstream <the URL you took from VSTS> master

Using Team Services online repository without visual studio

I am trying to use a team services account to store other related documents for a project such as some spreadsheets. I want the client to have access to it, but they are not programmers so I am not wanting them to use VS.
The client can access it directly without a problem and can download files, the biggest issue is they will need to be able to upload files as well. Without using a client of some sort they are limited to 10mb or less which won't work for them.
I cannot seem to get github for the desktop to access my online repository unless I first go into VS and clone it.
I am trying to avoid having to walk the client through doing that and would like to be able to use a GUI like github desktop from end to end.
We are all in a Windows environment.
I can create a new repository in github desktop, but cannot seem to figure out how to connect it to my remote (I can't find the URL for the remote anywhere).
I feel I am so close but just missing a couple items, any push would be appreciated.
GitHub Desktop is for GitHub. GitHub is a Git repository hosting service. Not surprisingly, the GitHub tool only works with GitHub.
You can use any general-purpose Git client to interact with VSTS Git repos. SourceTree is good.
You can use some git GUI or git command line to operate local repo.
Git GUI: as Daniel Mann said, you can use soucetree, or tortoiseGit etc.
Git command line:
you can download git here ->
git clone https://account.visualstudio.com/_git/projectname ->
enter email and password to clone ->
git add . (when you add some files) ->
git commit -am 'message'(commit the changes you make) ->
git push(push your commits into VSTS git repo) ->
git pull(pull VSTS git repo changes to localt).
I am just closing this out, thank you to both folks who did answer. I understand that I am using GIT and that GitHub Desktop is for Github. I was looking for the best way to work with a Github repository without using VS and how to access the team services repo for a client of mine. I set him up with Gitkraken which is working. I was never able to figure out how to get Github Desktop to properly clone and push items, but I did not spend a ton of time in it once I used Gitkraken.
Thanks again for taking a swing at it.
I accepted the answer I did because suggesting using the command line at least shows a understanding of my question and what I was looking for.
I know I am late to the game but I can confirm that tortoise git and getext also work fine with VSTS

Rstudio: Changing origin for git version control of project

I originally set up git in Rstudio while enrolled in the Data Scientist's Toolbox course at Coursera. Unfortunately, I did this in my phd project. The repository no longer exists on github. I am now attempting to write my thesis in rmarkdown using knitr and bookdown. I would like to use version control, both to learn proper git workflow and to have a structured back up of everything I have done in my thesis. However, I have been unable to change the version control repository in Rstudio.
I am unable to change this in the Tools > Version control > Project setup > Git/SVN menu. The Origin: textbox is unchangable.
I tried creating a new project using the old phd project's working directory. This also cloned the version control settings.
How do I change the origin to accomplish what is described above?
Git, Github and Rstudio are different things. You could use git as local version control tools. You might connect your local repo to Github account which is based on git by push/pull. Rstudio just makes a user interface for git and supplies the function to push the repo into remote server based on git to make version control(not only Github, but also Gitlab).
So for your issue, if you do not want to pay for github for a private repo, all of your code would be public and I don't think it is good before your finally finished your thesis. But version control could be made locally with git only. Just use git shell to control the version.
However, as a student, github could support private repo here for you. Just register and find your student package. Then just remove the url for remote repo after you cd to your workdir in command line, use the following code to find your remote url(mostly you might fing origin):
git remote -v
Then use this to remove them:
git remote rm origin
Now you could use version control locally. If you want to connect this repo to your remote github private repo, use this:
git remote add origin https://github.com/[YourUsername]/[YourRepoName].git
RStudio would find this information about git and support your following operation. Project in RStudio is different with git, although project support git as version control tool. So you need git in command line or shell to solve your problem.
This can be done by opening /your.project/.git/config
and editing the remote origin line(s), e.g. changing from git to https.
Restart Rstudio & you'll be prompted for your github username & password.
This is what worked for me for migrating from github to Azure
Go to the top right Git window in RStudio and click on the gear. Now click Shell (to open the terminal there).
#remove origin
git remote rm origin
#add new origin like Azure for me via HTTPS
git remote add origin https://USER#dev.azure.com/USER/PROJECT/_git/REPONAME
#push your local repro
git push -u origin --all
#in my case put in the PAT password if you needed to generate one.
After testing, I found some clue
Actually Rstudio is not really smart about this setting
It will first search for the git file in the Rproject folder where your Rporject file is located
if it could not, then it goes up to the folder contains your Rproject folder
However, for version control you only need coding files while RProject may contains some big files like .RData some pictures etc.
I don't find a way to manually disrupt this logic flow, the only thing you can do is to delete the current git repository setting files(which is .git folder and 2 other git setting files), then Rstudio may ask you if you want to init a new one.

Eclipse/Egit, Push to Remote menu choice is grayed out

I created a repository on GitHub. I set up a local git repository using Eclipse and Egit.
With Team > Remote > Push. I managed to push the local repo to the one on GitHub.
Now I expected to be able to use the Team > Push to Upstream (as well as fetch from upstream) as a one-click push (and pull/fetch), but this menu choice is not available (grayed out). I have to use Team > Remote > Push to each time manually fill in the info (ctrl+space helps).
Following this, I created a remote configuration and pushed from the repositories view, and I can see the remote GitHub repository listed under Remotes but still the Team > Push to Upstream command is grayed out in the menu.
Could someone please give me a hint as to what I have may done wrong?
Here's what I did and this worked fine:
Right click your project, choose Team→Show in Repositories View. You will switch perspectives and be in the Git Repositories tab.
Right-click "Remotes" and choose "Create Remote". For "Remote name", enter "origin". Click OK.
Click Change. Enter your information as you did during your initial push. Click Save.
You should now be able to push by merely right-clicking on your project, then Team→Push to Upstream.
Because the remote was added under the project in question, each project can have its own upstream origin and they will not interfere (whereas the Window > Preferences solution is a global setting).
Based on your description of what you did, it appears you attempted this - but possibly did not use the name "origin" for the remote, which is absolutely necessary. I stumbled across this solution by pure chance.
I had this problem and thankfully found a way to re-enable the "Push to Upstream" option.
Go to Window > Preferences > Team > Git > Configuration.
Select the Repository Settings tab and then the repository that represents your project.
Click "New Entry..."
The key is remote.origin.url
The value is the url you copy from github. It's usually offered predominantly on whichever site you register with.
Perhaps there is a neater way of achieving the same thing. Once I reached this far I stopped looking because it works now.
You need to have the following type of configuration in that repository's .git/config file:
[branch "master"]
remote = origin
The remote setting can be any of your remotes or just a value of .
You can edit the repository's config by selecting the Properties menu item from the context menu for the repository in the Git Repositories view.
I came here searching for solution to solve similar problem with bitbucket - although none of the two highest votes answer didn't work for me, it proved that I had option "Put branch...", when I tried to do this, it says "Non fast-forward", but when I successfully made "pull", I was able to push to upstream.
Maybe it will help someone :)
This post might be a little old, but I had the same issue with one of my repos the following information from this link worked for me: Adding a remote to an existing git repo
The part i want to highlight from that article is the following:
[branch "master"]
remote = origin
merge = refs/heads/master
When I made the change in the .git/config and refreshed eclipse the "push to upstream" link worked for me. Keep in mind, I am assuming that you have a remote configured in your Git perspective for your remote repository.
In my case all git commit/push operations are inactive. I fixed the issue by placing the repository folder under git directory.