You have been using git
to submit your work to GitLab.
But that isn’t what git
is really about.
git
is a version control (VCS) system; these are also called revision control systems (RCS) or source code management systems (SCMS)).
What version control systems do for you:
Provide backup against accidentally deleting files or chunks of files.
Allow you to find where a change was made that caused problems.
Allow you to revert to a previous version of your file, or to reverse a change you made.
With a remote repository:
Provide backup against your computer failing.
Synchronize your work across multiple computers
Allow you to collaborate with others.
To take advantage of these capabilities you need to develop some good practices:
Do all your work in your repository; don’t just copy things there at the last minute.
Commit and push often:
Each time you complete a substantial chunk of work (e.g. finish a problem or a part of a problem).
Each time you take a break.
Each time you run into a problem (include a reminder of the problem in your commit message).
Your commit message should be concise but useful.
You can provide more extensive information in a second paragraph
git
do.Pushing often also lets you know early if there is an issue with GitLab access.
https
, after changing your HawkID password you may need to use the Credentials Manager to remove the old authentication information for GitLab.If all goes well:
If you are working on your own and on only one computer, all you will need to do with git
is:
Commit changes to your local repository.
Push changes to your remote GitLab repository.
If you are using several computers, or collaborating with someone, you will also need to pull
changes from GitLab.
If you run into issues, you will need to use some more git
tools.
The most common operations are well supported by RStudio or GitLab:
Finding what changes were made to a file.
Retrieving an older version of a file.
Other operations are easier, or only possible, using the command line:
Moving and Renaming files.
Reversing a particular change.
git
Operations with RStudioYou can perform git
operations with:
The Tools > Version Control menu.
The Git tab.
Examples:
Make a change, longer commit message, push.
Review history, get old file versions.
Create folders, renaming files.
git
Operations with GitLabReview history, get old file versions.
Check out Blame
tab.
git
in a Shell/TerminalOccasionally git
will want to open an editor to let you enter a commit message.
The default editor it uses (usually vi
or vim
) is probably not useful.
You can register a more reasonable editor using
git config --global core.editor <editor>
Replace <editor>
with the name of a program that opens your editor when run from the command line with a text file argument.
On Linux you can use gedit
or nano
.
On Windows notepad
should work.
On Mac OS you should be able to use nano
.
Or use your favorite editor if you have one.
You only need to do this once on each system you use. The information you provide is included in a .gitconfig
file in your home directory.
If you don’t do this you may end up with git
using the vi
or the vim
editor, which is powerful but not intuitive if you haven’t used it.
vi
, type :q<return>
to get out.git clone <repository> [<directory>]
git status
git pull
git add <file1> <file2> ...
git commit
or git commit -m "<message>"
git push
git log [<file>]
git blame <file>
git mv <oldname> <newname>
git show <REVHASH>:<filepath>
vi
, type :q<return>
to get out.It you work on several computers, or collaborate with someone, you may need to resolve conflicts.
Conflicts are marked with <<<<<<
, ======
, >>>>>>
Remove the markers and adjust the code.
Some editors provide some support for this.
The git revert
command allows you to revert a specific commit.
git revert --help
provides some documentation.
This can lead to conflicts that will need to be resolved.
GitLab and GitHub are social coding platforms.
In addition to providing a remote repository, they provide a number of facilities to aid in collaboration.
Two important facilities are:
Issues for reporting and discussing bugs and other issues.
Merge requests (called pull requests in GitHub) for managing the incorporation of proposed changes.
Issues can be assigned to someone to deal with; assigning an issue will generate an email to the assignee.