This post will continue were the last post left off. We'll explore some more rea life scenarios. This includes things like tracking modifications on files, pushing our changes to the remote repo, checking out changes from the remote repo.
# Modify and add more file(s)
Typically, when working on a project, we'll be adding and modifying files in our directory. Here, we see 2 files
another.txt. The initial file was from the last post, all I did was add some more text to it. While the latter, is a new file I just created. All I've got to do is use the
git add command to stage them, then use the
git commit to record the changes.
vim file.txt vim another.txt git add file.txt another.txt git commit -m "COMMIT_MSG"
# Set up remote
Up till now, all the changes and tracking we've been doing has been on our local machine. This of course kinda kills the whole purpose of a Version Control Systems (VCS). But, don't worry that's what this section is for.
Here, we'll set up our remote repository. This remote repository is basically
git running on another IP-Addressable machine. Typically companies/teams might host their own git remote repo. But most people use a 3rd party hosted solution like github, bitbucket, gitlab, visual studio team services, assembla.
When you've decided which way to host git, go ahead and create a new git repo. Afterwards, locate the URL for that repo. Typically, they provide you with 2 URLs, 1 for https connections, 1 for ssh connections. In this post, we'll use the https URL.
Now with the URL, we can add the
remote repo to our
REMOTE_NAME, this is the name that we use to refer to this remote repo in our local repo.
REMOTE_URL, this is the URL for the remote repo.
git remote add REMOTE_NAME REMOTE_URL
With the remote repository setup, now we can push our changes to the remote repo, and we can also pull down changes from the remote repo.
git push REMOTE_NAME LOCAL_BRANCH
git pull REMOTE_NAME LOCAL_BRANCH
If you’re using an HTTPS URL, the Git server will ask you for your username and password for authentication. By default it will prompt you on the terminal for this information so the server can tell if you’re allowed to push.If you don’t want to type it every single time you push, you can set up a “credential cache”. The simplest is just to keep it in memory for a few minutes, which you can easily set up by running
git config --global credential.helper cache.
In the next post, we'll talk more about utilizing git in a more collaborative manner.