DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Git Operations With Visual Studio

Git Operations With Visual Studio

If you're more inclined to using Visual Studio, check out how you can still use it for your version control with Git.

Arvind Singh Baghel user avatar by
Arvind Singh Baghel
·
Mar. 19, 19 · Tutorial
Like (6)
Save
Tweet
Share
10.03K Views

Join the DZone community and get the full member experience.

Join For Free

Git

Git is an open source version control system which keeps the source code and tracks the changes in it. Git is mainly used for source code management in software development, where we keep source code in the git repository/directory/branch and it gives centralized access to the team. Git also keeps track of changes. Git has a set of commands and git cmd is used to perform git operations, like create a repository in git, create a local copy of the repository, create branches, add files, commit the changes, push the changes to a remote repository, and many more. Here is the list of all the git operations.

Microsoft Visual Studio has a Git client built-in directly into the IDE. We can perform most of the source control operations on git from Visual Studio directly. Visual Studio 13 update 1 has great support with git.

Create a Repository

A git repository, also called a repo, is a folder on the git which is used to keep and track project files and changes. The new repository can be created while creating a new solution in VS, simply by selecting "Create new Git repository."

create repository by Arvind singh

We can also create a repository from an existing solution. Go to Team Explorer and click on the "Publish" button in the bottom. It will create a new Git repository and open a "Publish view" to push the code to the remote Git repository.

clone repository by arvind singhClone Remote Repository

To get the code from the git remote repository, we clone the git repository and initialize a local repository. Go to team explorer; there is a plug icon on the top. Click on the plug icon and select the repository. Enter the repository path, then click on the "Clone" button. It will clone the repository and download all the commits and branches in the local copy of the repository.

Image title

Now, we have a copy of the repository. Make changes to the branch in files and perform another git operation.

View Changed Files

To see the uncommitted changes and files, go to Team Explorer and click "Changes."

git view change files by arvind singh

Stage (Index) File

To stage (or index) uncommitted changes, select the file, enter the comment, and click "Stage."

git stage

Commit/Push Modifications

To Commit/Push, you need to put some text in the comment area before committing the changes.

You can choose from three options.

Options

Actions performed

Commit Staged

Commit locally

Commit Staged + Push

Commit locally + Push to a remote repository

Commit Staged + Sync

Commit locally +

Pull (get updated info from a remote repository)

+ Push to a remote repository

git commit by visual studio by arvind singh

Result

The committed files will disappear from the change list and the commit id will be displayed.

git commit result

Push Modifications

To push locals commits to a remote server, go to Team Explorer Synchronization and click "Push."

push modification

Stashing Code

Visual Studio does not support this feature for now. You have to either stash in the command line or with a third-party software (SourceTree, …) or you can install a VS extension.

Read here about Git stashing.

Change the Current Branch

Go to "Team Explorer" and click on the branches.

visual studio change git branch

You can change the current branch by double-clicking on the branch (All the files are instantly updated).

git change branch

But if you still have modified files in the current branch, you cannot change the branch first. You have to commit, stash, or cancel the modifications.

git branch change

Your recently used branches are available in the bottom shortcut of Visual Studio.

change branch result

Create a New Branch

To create a new branch, go to the Team Explorer, click on “New Branch,” and you will have to indicate

  • the branch name
  • and the branch to be used to create the new one.

If you want to, switch to the branch you create (“Checkout branch”, but not like the TFS meaning)

create branch

Conclusion

In this article, we have seen some basic Git operations which we can perform with Visual Studio. We also saw that there are some limitations, such as stashing, which is not possible yet with Visual Studio.

Git Repository (version control) Branch (computer science) Commit (data management) remote

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Introduction to NoSQL Database
  • Distributed Tracing: A Full Guide
  • Benefits and Challenges of Multi-Cloud Integration
  • Effective Jira Test Management

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: