0
votes

I am trying to setup Git for a small team. I wish to use Visual Studio (VS 2015) as much as possible. I want each team member to have a local repo and we post our changes to a remote/central repo. I have an existing code base to start from.

What I have done:

  • Create local repo: From my code base folder, run ‘git init’
  • Loading my VS solution shows my Git repo (nice) and all files unstaged in Team Explorer | Changes view
  • I commit these changes to the master branch by choosing Commit All
  • Create remote repo: From my remote repo folder, run ‘git clone --bare c:\MyCodeBase’

I believe I have now established my local repo and created a fresh remote repo. Now, I tried to move on to working out the process of making a change to my local repo and pushing it to the remote repo. This is where I am failing.

What I did:

  • Created a feature branch off ‘master‘ in my local repo
  • Made a code change
  • Committed the code change to the feature branch
  • Merged the feature branch into the master branch.

Now I wish to push my local master branch to the remote master branch. (Is this a recommend workflow?)

My first step was to add a remote repo to VS. I did this in Team Explorer | Settings… However, I was a bit confused in that I was not provided a Browse button to specify the Fetch/Pull settings. Aren’t these supposed to be folders?

Now I am lost. How do I push my local master branch to the remote repo? In the Synchronization view, the Incoming Commits section states that the current branch does not track a remote branch (?). The Outgoing Commits section has a Push button, but it is disabled. I obviously do not get something.

Help with my specific questions is greatly appreciated. Any suggestions regarding overall workflow is also appreciated. I am simply trying to establish a simple workflow where we can work locally, update changes to a central/remote repo, and pull changes from that remote repo.

2

2 Answers

0
votes

To setup local git repo and remote git repo, your main steps are correct, but the path for the remote repo is incorrect.

Create remote repo: From my remote repo folder, run 'git clone --bare c:\MyCodeBase'

Assume you run the above command in c:\remote, you can only get an empty repo if you use the above command. The correct one should be git clone --bare c:/MyCodeBase, then you will has a bare repo in c:\remote\MyCodeBase.git.

Now in VS, you can add this remote repo by team explorer -> settings -> Repository Settings -> edit your remote repo path as c:/remote/MyCodeBase.git (it should be / not \).

Then you can publish your local master branch: team explorer -> Sync -> click publish (or you can select local master branch in Branches Page and right click publish).

Now you can push your local change to remote repo.

Note: since the remote repo need to be connected for other developers, you’d better hosted your remote repo on github, bitbucket etc, it’s safer and more convenient than you locate remote repo locally (especially when your local machine has no network or shutdown or destroyed, other developers can’t connected the reomte repo).

0
votes

If you use the current version of Visual Studio Code, it is very simple.

  1. Open VS Code
  2. Go to the Market Place (Left sidebar) and download "GitLab Workflow" extension
  3. Press Ctrl + SHIFT + P
  4. Type in "Git" > choose option "Git: Clone"
  5. Copy and Paste the HTTPS clone key from your remote repository
  6. Choose a file where your local repository is to be located
  7. From now on > Pull, Push, Sync, Fetch, etc. via Left sidebar