Return to Video

Setting Up Your Workspace on Mac - How to Use Git and GitHub

  • 0:01 - 0:02
    Now I'm going to walk you
    through the process of
  • 0:02 - 0:05
    getting your workspace set up on Mac.
  • 0:05 - 0:06
    And the process on Linux is similar.
  • 0:07 - 0:10
    There are also written instructions
    in the instructor notes.
  • 0:10 - 0:14
    If you're using Windows, there
    are instructions in the previous video.
  • 0:14 - 0:16
    First I'm going to download
    two files that are needed for
  • 0:16 - 0:20
    the set up I just showed you,
    one to enable tab completion, and
  • 0:20 - 0:24
    want to enable the special
    Git features in the prompt.
  • 0:24 - 0:26
    So I'll go to the webpage
    with the first file and
  • 0:26 - 0:29
    you can find the link to this
    file in the instructor's notes.
  • 0:29 - 0:33
    Then I'll right-click anywhere
    on the page and select Save As.
  • 0:33 - 0:35
    And I'll save the file in
    my Downloads directory.
  • 0:36 - 0:39
    Now I want to make sure that
    Hide extension is unchecked, so
  • 0:39 - 0:42
    that I can see the exact name
    the file is being given.
  • 0:42 - 0:46
    And by default,
    it's suggesting Redirecting.txt.
  • 0:46 - 0:50
    But I want to change this
    to git-completion.bash, and
  • 0:50 - 0:50
    then I'll Save the file.
  • 0:52 - 0:54
    Now I want to move the file
    to my home directory,
  • 0:54 - 0:56
    which I'll do using the Terminal.
  • 0:56 - 1:00
    Now when I first open the Terminal,
    I start out in my home directory, or
  • 1:00 - 1:04
    I can type cd ~ to get to
    the home directory if I need to.
  • 1:04 - 1:06
    Now I'll use the command mv,
    which stands for
  • 1:06 - 1:10
    move, to move the file I just
    saved into my home directory.
  • 1:10 - 1:12
    The first argument is
    the file I want to move,
  • 1:12 - 1:16
    which is in my Downloads directory and
    it's named git-completion.bash.
  • 1:16 - 1:22
    And I want to move it into the current
    directory while keeping the same name.
  • 1:22 - 1:24
    Then I'll go through the same process
    to save the second file linked in
  • 1:24 - 1:28
    the instructor's notes as git-prompt.sh.
  • 1:28 - 1:30
    Next, I'm going to create
    a file called .bash_profile,
  • 1:30 - 1:33
    which contains configuration for
    the Terminal.
  • 1:34 - 1:38
    I recommend using the configuration file
    that I used when filming this course.
  • 1:39 - 1:42
    To do that, you can download the file
    called bash_profile_course in
  • 1:42 - 1:43
    the downloadables section.
  • 1:45 - 1:49
    Next, use the Terminal to move
    this file to your home directory.
  • 1:49 - 1:53
    You should name it .bash_profile and
    don't forget the dot at the beginning.
  • 1:53 - 1:57
    Now if you already have a bash profile,
    then don't run this command, and
  • 1:57 - 1:58
    instead you can copy and
  • 1:58 - 2:01
    paste the content from this file
    into your existing bash profile.
  • 2:03 - 2:04
    And if you're running Linux,
  • 2:04 - 2:09
    then you might need to name this file
    .bashrc instead of .bash_profile.
  • 2:09 - 2:13
    Now I don't see any changes made to my
    prompt yet, and that's because I'll
  • 2:13 - 2:16
    need to close and reopen the Terminal
    before the changes take effect.
  • 2:16 - 2:19
    I'll do that at
    the the end of the video.
  • 2:19 - 2:22
    In case you're curious about
    what's in this bash profile, or
  • 2:22 - 2:23
    if you'd like to pick and
  • 2:23 - 2:27
    choose just the lines you're interested
    in, I'll go through what each line does.
  • 2:27 - 2:31
    Now, don't worry if you don't
    understand how each line works though.
  • 2:31 - 2:35
    Even experienced Unix programmers
    frequently copy and paste this kind of
  • 2:35 - 2:37
    thing from their friends,
    rather than writing it from scratch.
  • 2:39 - 2:42
    This first line loads one of
    the files you downloaded earlier and
  • 2:42 - 2:43
    enables tab completion.
  • 2:44 - 2:47
    These lines define some colors,
    which will be used in your prompt.
  • 2:48 - 2:51
    This line loads the other
    file you downloaded earlier.
  • 2:51 - 2:52
    And it's necessary for
  • 2:52 - 2:54
    the git related stuff like commit
    IDs to show up in your prompt.
  • 2:56 - 2:58
    This line is what makes sure that
    the asterisk will be shown in your
  • 2:58 - 3:01
    prompt if you make changes
    in a git repository.
  • 3:01 - 3:04
    And this line actually defines
    what the prompt will be.
  • 3:04 - 3:07
    The prompt will show
    your username in purple,
  • 3:07 - 3:11
    the commit you currently have checked
    out or other git related stuff in green.
  • 3:11 - 3:14
    And the director URN followed
    by a dollar sign in blue.
  • 3:14 - 3:17
    Then any text after that will be
    displayed in the default color.
  • 3:17 - 3:20
    If you're curious to learn more
    about how prompts work in bash,
  • 3:20 - 3:23
    check out the link in the instructor's
    notes, but it's not necessary for
  • 3:23 - 3:25
    the rest of this course.
  • 3:25 - 3:28
    Next, it's important to make sure
    you can launch your favorite text
  • 3:28 - 3:29
    editor from the Terminal so
  • 3:29 - 3:33
    that you'll be able to set it as
    your default editor within git.
  • 3:33 - 3:35
    I'll show how to do this for Sublime.
  • 3:35 - 3:37
    If you're using another text editor,
  • 3:37 - 3:41
    I recommend that you Google to figure
    out how to use it from the Terminal.
  • 3:41 - 3:45
    Now, I can launch Sublime from the
    Terminal by running this long command.
  • 3:45 - 3:49
    Where this is where Sublime
    is stored on my computer, but
  • 3:49 - 3:51
    I'd like to have a shortcut.
  • 3:51 - 3:55
    To create one I'll use Sublime to
    add a line to my bash profile.
  • 3:56 - 3:59
    Files with a dot at the beginning of
    the name don't usually show up in
  • 3:59 - 4:01
    file system explorers, so
  • 4:01 - 4:04
    I'm going to have trouble opening
    my batch profile with Sublime.
  • 4:04 - 4:07
    To fix this I'll use the trick
    of moving my bash profile
  • 4:08 - 4:11
    to a file without a dot at
    the beginning of the name.
  • 4:12 - 4:15
    Then to open the file in Sublime, I'll
    first navigate to my home directory,
  • 4:15 - 4:19
    which I can do by pressing Cmd+Shift+H.
  • 4:19 - 4:22
    And then I'll select
    the file bash_profile.
  • 4:22 - 4:25
    Then I'll add this line to it to
    make the subl command stand for
  • 4:25 - 4:27
    the same command that you
    saw me enter earlier.
  • 4:29 - 4:30
    You can copy and
  • 4:30 - 4:32
    paste this line from the instructor's
    notes if you're using Sublime.
  • 4:34 - 4:36
    Now I'll save the file and
  • 4:36 - 4:41
    I'll change the name back to have a dot
    at the beginning using the Terminal.
  • 4:41 - 4:41
    If I don't do this,
  • 4:41 - 4:45
    then the bash profile won't take
    effect when I open the Terminal.
  • 4:45 - 4:48
    Again, this command won't work
    until I've restarted the Terminal.
  • 4:49 - 4:51
    Now I'll configure git to
    use Sublime as my editor for
  • 4:51 - 4:53
    things like commit messages.
  • 4:53 - 5:00
    To do that I'll run git config
    --global core.editor and
  • 5:00 - 5:04
    here I need to put in double quotes
    the command to open my text editor.
  • 5:05 - 5:09
    For Sublime that's subl -n -w.
  • 5:09 - 5:13
    Where -n will open
    Sublime in a new window,
  • 5:13 - 5:16
    and -w will wait until you close
    your file before continuing.
  • 5:18 - 5:19
    If you use a different editor,
  • 5:19 - 5:23
    you will need to modify this part of the
    command to use the editor that you like.
  • 5:23 - 5:26
    See the instructor's notes for
    more details.
  • 5:26 - 5:29
    Next I'll run these two
    git config commands,
  • 5:29 - 5:32
    which will come in handy
    later in the course.
  • 5:32 - 5:33
    Please copy and
  • 5:33 - 5:36
    paste these commands from
    the instructor's notes and run them.
  • 5:36 - 5:39
    Finally I'll close the Terminal and
    reopen it.
  • 5:39 - 5:42
    Now I can see that my prompt has
    changed to become more colorful.
  • 5:43 - 5:46
    And if I want to view my
    bash profile using Sublime,
  • 5:46 - 5:49
    I can run subl .bash_profile.
  • 5:49 - 5:52
    Remember to close and reopen your
    Terminal when you're finished, or
  • 5:52 - 5:53
    your changes won't take effect.
Tytuł:
Setting Up Your Workspace on Mac - How to Use Git and GitHub
Opis:

more » « less
Video Language:
English
Team:
Udacity
Projekt:
UD775 - How to Use Git and GitHub
Duration:
05:55

English subtitles

Revisions Compare revisions