Starting at the command line
You can start the process at any of our repositories. Last time we started in the VisualStudio
repository and then pulled the changes down to the CommandLine
and GitDesktop
repos. This time, let's start at the command line.
Open Visual Studio and point it to the project in your CommandLine
directory. Just to be certain, right-click on Solution, select Open Folder in File Explorer, and make sure you are in the right directory.
To keep this example very simple, we'll just add another line to Program.cs
:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Console.WriteLine("I just added this in Visual Studio");
Console.WriteLine("I just added this in the command line repo");
}
}
Normally you would make many more changes before checking in, but again, this is a demo and we're more interested in using Git than we are in fussing with this silly program. Save all your files and at the command line get the status by entering:
git status
This will give you output that looks like this:
Figure 2.20: The command line indicating one file has been modified
The key piece of information is the modified file. That is just as it should be, as that is the file we modified. You can now add it to the index and then commit it:
git add ProGitForProgrammers/ProGitForProgrammers/Program.cs
git commit -m "Add writeline indicating we are in command line"
On the other hand, you can combine these two steps with the -a
flag:
git commit -a -m "Add writeline indicating we are in command line"
You will want to draw a distinction between untracked files and modified files. Untracked files are outside of Git and cannot be manipulated inside Git until they are added; modified files are tracked by Git but have changed since the last commit.
If we are happy with the commit we've added, we can (optionally) push it to the server:
Figure 2.21: Pushing our commit to the remote repository
We'll want to do that because we want to share this code with the other programmers.
Pulling to GitHub Desktop
Switching to GitHub Desktop, we see that it already knows there is something to pull, as we saw last time. (If it doesn't, push the Fetch button, which will go to the server to see if there is anything to bring back.)
That's two repos that are identical, but the VisualStudio
repo is not yet up to date. Let's return to Visual Studio in the VisualStudio
folder.
Pulling to Visual Studio
Open the Git menu item, and select Pull
. Watch your source code and see the third line pop into existence. Once again, the three local repositories and the remote repo are all in sync.