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
git --versionIt 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:
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.
Go to the folder where you keep projects, for example:
bashcd ~/DocumentsClone with the HTTPS address shown on the project's page:
bashgit clone https://github.com/example/repo.gitGo into the new folder:
bashcd repo
Public projects clone without signing in.
Save a change
Edit a file, for example with
vi README.md.See what changed:
bashgit status git diffChoose the files to include, then commit with a message:
bashgit 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
git pull
git pushBoth 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
.sshfolder of your user folder. If you already use SSH keys on this PC, addresses such asgit@github.com:example/repo.gitwork.
To create an SSH key, if Windows OpenSSH is installed:
ssh-keygen -t ed25519Then 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
| Command | What it does |
|---|---|
git clone | Downloads a project |
git status | Shows changed files |
git add | Chooses changes for the next commit |
git commit | Records the chosen changes |
git pull / git fetch | Gets changes from the server |
git push | Sends your commits to the server |
git branch / git checkout | Lists, creates and switches branches |
git log | Shows history. Press q to leave |
git diff | Shows what changed |