Visual Studio 2022 and Git issue

T.Zacks 3,986 Reputation points
2022-03-18T12:35:50.79+00:00

i am comfortable with TFS. from TSF we can get latest a single file when some other user checked in that file but when using GIT then i am not getting such functionality from VS2022 IDE. when a user A commit & push a file frmMain.cs file then how could i pull that file only instead of all pushed files?

when a user A **commit & push a file in git but i have not that file in my IDE then how could i pull that file only instead of all newly pushed files?

please guide me for my above 2 questions. thanks

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,414 questions
0 comments No comments
{count} votes

Accepted answer
  1. Karen Payne MVP 35,201 Reputation points
    2022-03-18T17:55:40.94+00:00

    when a user A **commit & push a file in git but i have not that file in my IDE then how could i pull that file only instead of all newly pushed files?

    When working in a team environment one should always perform a fetch when starting work. If a team mate makes changes they should notify you or you need to perform a fetch. As things get more complex one should look at commit details. Dependent on complexity in some cases Visual Studio will do a auto merge or if not you need to open the merge editor.

    But for adding a form, do the fetch then pull.

    In the screenshot below I opened the same project in different folders, one with VS Code, one with Visual Studio. In Visual Studio, added a project, did a fetch in VS Code, pulled in the new project, added a comment, commit/pushed then fetched in Visual Studio and pulled.

    184711-f1.png


2 additional answers

Sort by: Most helpful
  1. AgaveJoe 26,246 Reputation points
    2022-03-18T16:21:15.1+00:00

    Your question does not make a lot of sense. If you just did a commit and push then you already have the latest files.

    If someone else on your team did the commit and push the you can do a fetch or sync to get the latest files. However, you are not using Git as recommended in the openly published documentation. Set aside time to learn how Git works and come up with a work flow.


  2. Bruce (SqlWork.com) 58,126 Reputation points
    2022-03-18T16:57:15.917+00:00

    git is a peer repo system. a remote is just an agreed upon peer to sync with. when you do a clone, your box now is a complete independent git repo. you then branch, checkout/check into your local repo. at some point you decide share your repo changes with the shared (remote) repo. this requires two steps

    1) update your local repo with all other changes made to the remote repo (pull/fetch)
    2) push your repo to the remote (which makes it match your repo)

    to do what you want to do, you create a feature branch for your working code (checkout and branch). then you can pull from the remote which will not affect your branch. your local repo's main branch will match the remote repo (plus any other branches on the remote). you can then cherry pick a file from the main (or any branch) to your feature branch

    if you committed your changes locally without a branch, then you can branch at a commit. if you have not committed you can stash and branch

    in summary, if you want to work locally with remote changes affecting you local work, you should create a branch on checkout. when ready, you'd pull, then merge your branch to mainline. then push