Git is an open source tool that allows you to track, back up, and manage code projects. You can use it to keep an external copy of your project on a site like GitHub – to collaborate, back up, or show off your project to other people. Alternatively, you might have existing code that you want to import into SWAN.
Clone a remote repository
To use files from an existing git repository in your SWAN session:
- Click Git > Clone a Repository.
- Enter the URL of the git repository.
- Click Clone.
SWAN will display a success message when it clones the repository.
Create a git repository
To create a git repository for your entire SWAN session:
- Make sure you’re in the home folder. Click on the folder icon under the Filter field in the Files pane.
- Click Git > Initialize a repository in the top navigation menu.
- Click Yes.
Configure git
To tell git who you are:
- Click Git > Open Git Repository in Terminal.
SWAN will open a console window in a tab. - Enter:
git config --global user.email [your email address]
For example:git config --global user.email you@example.com
- Enter:
git config --global user.name [your name]
For example: git config --global user.name KimFang
Connect git to a remote repository
To connect your git repository to a remote repository, so you can copy changes back and forth:
- Find the URL for the remote repository. If you don’t have a remote repository set up yet, create one and copy the URL. It will look something like https://github.com/username/reponame.git
On GitHub, you can typically click on the Code button on a project’s page to view its repository URL. - Find your login details for the remote repository. You might need your usual password or – more commonly – a temporary access token for the app.
On GitHub, click your profile picture > Settings, then Developer settings and Personal access tokens to create a token to use when logging in to GitHub from SWAN. Make sure you tick the repo box under Select scopes to ensure you’ll be able to push to the repository from SWAN. - Click Git > Add Remote Repository.
- Enter the URL for the remote repository.
- Click OK.
Send files to your remote repository
- Click Git > Open Git Repository in Terminal.
SWAN will open a console window in a tab. - Enter git status to see which files and folders are available to be added to git.
bash-4.2$ git status On branch master No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) .Renviron .bash_logout .bash_profile .gitconfig .ipython/ .jupyter/ .local/ IMPORTANT.txt cloudstor/ public/
For example, in the above output, I could add
nothing added to commit but untracked files present (use "git add" to track)public/
andcloudstor/
folders.cloudstor/
is a link to my entire CloudStor drive, so I don’t want to add that to git! I do want to add the files in thepublic/
folder, though. - Enter
git add [file]
to start git tracking the file.
For example, I want git to track all the files in mypublic/
folder, so I usegit add public/*
- Enter
git commit -m "[commit message]"
to tell git that you’re ready to send a copy of the added files to the remote repository.
For example,git commit -m "First commit using SWAN"
.
Git will process the file changes.
bash-4.2$ git commit -m "First commit using SWAN" [master (root-commit) 0e20193] First commit using SWAN 15 files changed, 194517 insertions(+) create mode 100644 public/11-0.txt create mode 100644 public/1342-0.txt create mode 100644 public/1400-0.txt create mode 100644 public/1661-0.txt create mode 100644 public/1952-0.txt create mode 100644 public/2701-0.txt create mode 100644 public/4300-0.txt create mode 100644 public/84-0.txt create mode 100644 public/98-0.txt create mode 100644 public/pg105.txt create mode 100644 public/pg174.txt create mode 100644 public/pg20228.txt create mode 100644 public/pg345.txt create mode 100644 public/pg68301.txt create mode 100644 public/research-links.txt
- Click Git > Push to Remote.
- Enter your username and password or personal access token.
- Click OK.
SWAN will display a success message if the push was successful.