-
Notifications
You must be signed in to change notification settings - Fork 39
Github in Vs
Working with open source means that you most likely don't belong to the team who already collaborates on a project. However, there must be a way for you to join a project. You need some way to get code to work with. The first step for preparing to work with open source code is forking.
Navigate to a repository you want to work with.
Click the fork button, which is in the top right corner.
Note how repository name changes from
csinn/CSharp-From-Zero-To-Hero
to
Your-Github-Name/CSharp-From-Zero-To-Hero
This means that you can now edit the code on your own repository. This doesn't make you the owner of the repository, but this enables you to do all the things that you would normally with your own code. You just created a remote repository on your GitHub account. Of to the next step!
Your remote repository is not of much use, unless you can work on it locally. In order to work on it locally, you need to pull the remote repository enabling you to work on local repository.
Clone is the command that moves remote repository to your local machine.
The url you need for the clone command can be found a bit under fork button, called "Clone or download".
Click the button and it will give you a link to your repository. Copy it.
Now open visual studio, go to Team Explorer.
Make sure you are in the Team Explorer tab (1). Click the connect button(2).
Click Clone (3), copy-paste the repository url (4) and hit the clone button (5).
You should see a new item in Local Git Repositories.
Cloning a new repository doesn't open it by default. Visual Studio also doesn't know which solution should be opened when a new repository is cloned.
Double click the new item in Local Git Repositories in order to open it.
If repository name is bolded, it means it is now active.
The same should be done to solution. Hit home button of Team Explorer and double click the solution (probably the only item in the list) you want to open.
If the solution is open, it will be bolded.
If the solution is open, it will be bolded.
Congratulations! This means you know are working on a local repository, the right solution of a forked repository.
Main branch of repository is called master branch. Normally, we don't work directly on it. The fork that you did might not have been from master. Also, you might want to switch to different branches in the future. For forking purposes, most common branch will be
ChapterX/Homework/Y
The process of switching to a branch is called Chckout. You can do a checkout by going to team explorer, home (1) and hitting the branches button (2).
The currently active branch is bolded (1). If you want to checkout a different branch, double click it (2).
Eventually you will have done some work. If you don't do anything, your work will be only on your end. In order to move local files to local repository, you need to stage and commit them.
In Visual Studio, both steps (stage and commit) are done at the same time by default.
Open Team Explorer and click Changes button.
You will see a text box for a commit message (1) (message for a change list summary).
Below you will see all the changes that happened after your last commit (2).
Describing the changes are mandatory in Visual Studio. Describe what change did you make and hit the commit all button (3).
Your files are now safe in local repository.
Commit early and often, because it's nice to have descriptive history and revert to a certain point if needed.
Your changes are in local repository. You need to move changes from local to remote repository so that it can be shared with other people.
In order to move changes from local to remote repository, you will need to do a push.
Like in previous steps, first go to Home menu of Team Explorer. Click Sync button.
In this window you will see outgoing commits (1) and incomming commits (2).
Outgoing commits are the commits that you made locally.
Incomming commits are commits that someone made on the remote repository.
If you have incomming commits you will need to download the changs first.
This is done using the pull command, but about it later.
If there are no incomming commits, you are free to press the push button (3).
Note how all the outgoing commits are gone. This means the changes are now safe in remote repository.
People don't know you and they don't trust your changes. Your changes cannot be just merged with the target branch of the source branch you forked from. You need to make a request for your changes to be reviewed and accepted by the collaborators of the other repository.
In open source world, request for changes is called a Pull Request (PR).
PR is like a post on a forum which collaborators will review.
In order to create a PR from GitHub, open your repository in browser.
Click the New pull request button.
A new window will open. There you will need to select two branches:
source branch (1)- a branch which you want to integrate and
target branch (2)- a branch to which you want to merge your changes.
Below the branches selection, you can see all the commits that will be included in the change list (3).
After you made a selection for source and target branches, click the Create pull request button (4).
A new window will open. There, it's quite straightforward:
Name your PR (1) and summarize all the changes (2).
When you are done, click the Create pull request button (3).
That is it! Your PR is created and people will take a look at it as soon as they see it :)
After you forked a repository, you will end up with 2 repositories:
Origin- your own remote repository,
Upstream- original source repository that you cloned.
If you don't do anything, in VS you will only have git link to origin.
This means that if something changes from upstream, you won't be able to sync it with your origin.
You need to add a link between your local repository and remote upstream.
First, go to home (1) of Team Explorer and click Settings button (2)
Click repository settings
Expand the remotes menu (1) and click Add (2)
In the new window, enter the new remote name(1) (recommended to call it upstream), paste the forked repository URL (2)
and hit the add button (3).
That's it! next time you fetch/pull (1) or push (2) you will be able to select the upstream (3)
One more thing to note. If something changes on any remote, you won't see those changes locally, unless you fetch that remote.
So to see if there is a new homework you can fetch upstream master OR as mentioned before.
There is an alternative, more visual way to do so too.
Open branches window. You will notice origin (1) as well as upstream (2)
Expand upstream, right click on master (3), press fetch (4)
That's it, you will see all the new branches and will no longer need to re-fork.
You can simply create a new branch from the selected remote branch and you're good! :)
Fundamentals of practical programming
Problem 1: International Recipe ConverterLesson 1: C# Keywords and User Input
Lesson 2: Control Flow, Array and string
Lesson 3: Files, error handling and debugging
Lesson 4: Frontend using WinForms
RESTful Web API and More Fundamentals
Problem 2: Your Online Shopping ListLesson 5: RESTful, objects and JSON
Lesson 6: Code versioning
Lesson 7: OOP
Lesson 8: Understanding WebApi & Dependency Injection
Lesson 9: TDD
Lesson 10: LINQ and Collections
Lesson 11: Entity Framework
Lesson 12: Databases and SQL