Skip to content

Use Git ​

Git is included in Ubuntu Terminal, so git works as soon as the app is installed. This page takes you from a first clone to a first push.

Git is a tool that records the history of a project's files. If it is new to you, the commands below are enough to get a copy of a project and save changes to it.

Check that Git is there ​

bash
git --version

It prints a version number. No separate Git for Windows installation is needed.

Tell Git who you are ​

Git puts a name and an email address on every commit. Set them once:

bash
git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Clone a project ​

Cloning downloads a project and its history into a new folder.

  1. Go to the folder where you keep projects, for example:

    bash
    cd ~/Documents
  2. Clone with the HTTPS address shown on the project's page:

    bash
    git clone https://github.com/example/repo.git
  3. Go into the new folder:

    bash
    cd repo

Public projects clone without signing in.

Save a change ​

  1. Edit a file, for example with vi README.md.

  2. See what changed:

    bash
    git status
    git diff
  3. Choose the files to include, then commit with a message:

    bash
    git add README.md
    git commit -m "Fix a typo in the README"

If you leave out -m, Git opens vi for the message. Type it, press Esc, then type :wq and press Enter. See Edit files with vi.

Get and send changes ​

bash
git pull
git push

Both need a network connection. git push, and git pull on a private project, also need you to sign in to the server.

Sign in ​

There are two common ways to prove who you are to a Git server.

  • HTTPS: Git asks for your user name and a password or access token when you push. Most hosting services expect a personal access token in place of your account password. Create one in your account settings on the service.
  • SSH: you use a key pair in place of a password. Ubuntu Terminal uses the OpenSSH that comes with Windows, and the keys in the .ssh folder of your user folder. If you already use SSH keys on this PC, addresses such as git@github.com:example/repo.git work.

To create an SSH key, if Windows OpenSSH is installed:

bash
ssh-keygen -t ed25519

Then add the contents of the .pub file to your account on the Git service. Never share the file without .pub: that is your private key.

Commands that work ​

CommandWhat it does
git cloneDownloads a project
git statusShows changed files
git addChooses changes for the next commit
git commitRecords the chosen changes
git pull / git fetchGets changes from the server
git pushSends your commits to the server
git branch / git checkoutLists, creates and switches branches
git logShows history. Press q to leave
git diffShows what changed

Next steps ​