2018-08-30
|~3 min read
|461 words
Continuing my learnings re: Git. I wanted to better understand the use cases for three Git commands: 1. Clone 2. Pull (or Fetch and Merge) 3. Push
Thinking in terms of use cases helped me separate these different commands.
This is a case for $ git clone
.
Before you clone the repository, you’ll want to be in the desired directory. For example, if you want to store the repo locally in your documents folder, you’ll want to verify that your path is ~/Users/[Your User Name]/Documents
.
Now that you’re where you want to be, pull down a repository to create a local copy. To do this, use the command $ git clone [ssh]
or $ git clone [https]
.
I prefer the [ssh]
because then I only have to put in my RSA password instead of my username and password, though it does mean managing a key and a second password, so YMMV.
(Note: I found the Github tutorial here to be really easy to follow for this step of generating an SSH key.)
This is typically done once at the beginning of a project to provide a local copy.
This is a case for $ git pull
(or $ git fetch
and $ git merge
). These commands will update your local copy with the new commits from the remote repository. Again, you’ll be pulling from the shared repo, but instead of a blank slate, you’ll be merging into the directory where you already have your work. This means that if your branch and the origin have diverged, they will be merged (though how is still up to you as there are a number of merge options available).
This is a case for $ git push
.
Now that you’ve done your work, you want to push it back to the shared Repo for others to be able to collaborate.
Here’s where $ git push
comes in handy.
- Navigate to the directory in terminal.
- Use the command
$ git push
- Again, you’ll need to validate your credentials - login/password and/or your RSA passphrase.
Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!