Git
You have almost certainly used Git, or at least Github or Gitlab. Linux has a full-featured Git command-line client. This isn't a guide on how to use Git, rather just a quick introduction for people who have not used it and a quick reference for people who want to use it on the Linux CLI.
Git was invented to manage version control on software development projects. It also manages multiple developers contributing to one codebase without undoing or overwriting other developers' changes. It also provides a convenient way to maintain a codebase in multiple locations, for instance on your laptop, on your development server, on your production server, and even on Gitlab's servers.
You can install git the same way as any other package. Like tmux, it should already be pre-installed on all of our HPC servers.
$ dnf install git $ apt install git $ pacman -S git
First thing to do before you start doing anything is to set your username and e-mail address. Git requires this so it can ID who makes changes to codebases.
$ git config --global user.name "John Doe" $ git config --global user.email johndoe@example.com
Now if you have an already existing git repo, you can clone it to your current working directory with git clone
$ git clone https://gitlab.com/username/project
This will create a new directory in with the entire codebase in it.
To create a new git repository, you will want to create a new folder, change directory into it, and initialize the repo with the command 'git init'
$ mkdir my-project $ cd my-project $ git init
So you can add and change files, but that won't be recognized by the git repository until you commit. Committing is really a two-step process. First, you have to add the files that you want to commit, then you commit the change. Most commonly, especially for beginning, you will add all files to the commit with 'git add -a' and then you will commit with 'git commit'
$ git add -h $ git commit
If you cloned a repo that you own and want to push the commit back to the origin branch, you can do that with 'git push origin master'. And if there are changes that you want to copy to your local install, you do that with 'git pull'
$ git push origin master $ git pull
Now say you made some changes to some code and you broke everything, no worries, you can revert all changes made back to the most recent commit with 'git restore'. 'git restore file.txt' will restore one file.
$ git restore $ git restore onefile.py
This is the very rough basic quick start guide. There are literally thousands of other features for Git. Of course there is a man page. Similarly, it is self-documented through the help function. For instance you can type 'git help restore' and it will print to the console useful information about different options for restore. And of course you can type "how to check-out git" into duckduckgo to find out how to check-out a git repo that you don't own.
Quick Reference Basic Commands
Command | Effect |
---|---|
git clone https://gitlab.com/username/repo | Clones existing repo on gitlab to your current directory |
git init | Turns the current directory into a git repository |
git add -a | Adds all of the files that have been changed to Staging to be committed |
git commit | Commits the changes to a create a new version |
git restore | Rolls back all changes to the most recent commit |
git push origin master | Pushes commit to the main branch |
git pull | Pulls commit from the main branch |
git help | Shows options for git |
git help option | Shows help for whichever option you select (for instance commit, or restore) |