Setting up your laptop for Git and Bitbucket
Follow these instructions to get your computer set up to use Git and Bitbucket.
If you want to learn more about Git, consider enrolling in Mastering Git.
- Sign up for a Bitbucket account
-
If you already have a Bitbucket account, skip to the next section.
- Go to in your browser.
- Click Continue with Google and sign in with your 1Hope email.
- Click Create your account.
- For your username, enter your 1Hope username followed by -hope (e.g., sd1234-hope if your Hope email address is sd1234@hope.edu).
- Click Continue.
- Leave the first 2 questions blank.
- Choose Student for your role, and Application Development for how you plan to use Bitbucket.
- Submit your responses.
- Set up your SSH key
-
Generate a new key
If you already have a key and know where to find it, skip this heading and go to Copy an existing key to your laptop.
These instructions assume you are on a laptop running Windows.
- Enter cmd into the Windows search bar and execute the Command Prompt app.
- Enter ssh-keygen and press Enter to begin the process of creating a key.
- Press Enter to accept the default location for the key.
- If you’d like to protect your SSH key using a passphrase, enter one now. Otherwise press Enter twice to skip adding a passphrase.
- Enter the following command to change to your account’s home directory.
cd /d %USERPROFILE%
- Make sure the Google Drive app is running. This doesn't mean navigate to Google Drive in a web browser!
- Execute the following command to copy the .ssh folder to a folder named SSH-keys in your Google Drive.
xcopy .ssh "g:\My Drive\SSH-keys\"
Be sure to enter the double quotes shown above. This is because the My Drive folder contains a space in its name. - Press WIN – E to open a Windows Explorer window.
- Navigate to G:\My Drive\SSH and verify it contains the files id_ed25519 and id_ed25519.pub.
These are your private and public keys, respectively. There may or may not be other files in the SSH directory; it's OK either way. - In the command prompt, execute the following command to display the contents of your
public key.
type .ssh\id_ed25519.pub
This literally means to type the word type. - Select the text that is displayed and copy it to your clipboard.
- Move on the the Upload the key to Bitbucket section, skipping the section Copying an existing key to your laptop
Copy an existing key to your laptop
In these instructions, you should replace path\to\folder\with\key with the full path to the folder containing your public and private keys. This path should include the drive letter on your computer.
For example, if the keys are in a folder named SSH-keys in your My Drive Google Drive folder, you would use G:\My Drive\SSH-keys.
- Enter cmd into the Windows search bar and execute the Command Prompt app.
- Execute this command to ensure you are in your account's home directory.
cd /d %USERPROFILE%
- Execute this command to copy the files to a folder named .ssh in your account's home
directory.
xcopy "path\to\folder\with\key" .ssh\
The trailing \ character in .ssh\ indicates to the xcopy command that .ssh refers to a folder (directory) and not a file.
If you don't enter the trailing \, you will be prompted for this information, and you should enter D for directory. - Execute this command to verify the keys have been copied correctly.
dir %USERPROFILE%\.ssh
The file listing should contain the files id_ed25519 and id_ed25519.pub (or possibly id_rsa and id_rsa.pub if you created the keys a while ago).
These are your private and public keys, respectively.
There may or may not be other files in the SSH directory; it's OK either way. - In the command prompt, execute this command to display the contents of your public key:
type .ssh\id_ed25519.pub
You should see a long string of text displayed that starts with -----BEGIN OPENSSH PRIVATE KEY-----. - Select that text and press CTRL – C to copy it.
- Move on to the section Upload the key to Bitbucket
- Upload the key to Bitbucket
-
You may be able to skip this section if you copied a previously existing SSH key to your laptop, and it's been uploaded to Bitbucket before.
Go ahead and follow these steps; if you've already uploaded the SSH key, you'll get the message "Someone has already added that SSH key" when you attempt to save the new key.
- Switch back to the browser tab for BitBucket.
- Click the Settings "gear" next to your account avatar in the top right corner of the page.
- Choose Personal Bitbucket Settings.
- Click on the SSH keys link from the left menu.
- Click the Add key button.
- Enter hopekey for the Label.
- Paste the copied SSH key into the Key box.
- Click the Add Key button.
- Configure Git on your laptop
-
Git contains many configuration options. Each of them can be specified for a particular scope:
- system (every user on a computer)
- user (all repositories for a specific user, also called global configuration)
- per repository (also called local configuration)
Options at lower levels of the hierarchy override those found at higher levels. For instance, a global configuration value overrides a system option's value, and a local configuration value overrides a global option's value.
You'll specify global values for 5 configuration options: your name and email address, the editor to use to edit commit messages, how to handle line feeds on our Windows machines, and the name of the default branch to create for new repositories.
- Switch to a command prompt window or start one if you don't have one running.
- Execute the following command to set your name:
git config --global user.name "Your name"
Replace Your name with your first and last name. - Execute the following command to set your email address:
git config --global user.email emailReplace email with your 1Hope email address, including the @hope.edu part. - Execute the following command to make Notepad your default text editor:
git config --global core.editor c:\\Windows\\System32\\notepad.exe
Those are backslashes, located above the Enter key on your keyboard. Two of them are entered to "escape" the backslash. - Execute the following command to specify how Git should handle conversions between
Windows line endings (carriage return followed by line feed) and Mac/Linux line endings
(line feed only):
git config --global core.autocrlf true
This setting for the core.autocrlf property tells Git to automatically convert the 2-character sequence CR LF produced by windows editors to just LF when staging a file, and to convert each LF character to CR LF when checking out the file.
- Execute the following command to specify the branch name for the branch created by
git init for new repositories.
git config --global init.defaultBranch main
Historically the default branch has been named master, but people have realized the term master has some negative cultural ramifications and have begun moving to main instead.
Repositories created on GitHub use main as the initial branch automatically; at this time, Bitbucket appears to still create a branch named master if you don't specify the initial branch's name when creating the repository.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam quis risus eget urna mollis ornare vel eu leo.
workP. 616.395.7530
cschair@hope.edu