Git commands

From Vrieze Wiki
Jump to navigation Jump to search

Github is a great place to host code, whether you use it to manage changes, post a final(-ish) version of code, or collaborate and share with others. It can be easier to use git than to email scripts, or point someone to a script on the supercomputer.

Starting a repo

First, you can create a directory (on any computer) and put some files into it. Then to initiate a repo, install git and run something like

git init

Then, to add all the files, run the following (to add specific files just run git add <filename>):

git add .   ## to add all files
git add <filename> ## to add specific files

Finally, to commit the files to the repo, you can run commit

 git commit -m "message about commit" ## to commit
 git commit --dry-run -m "message about commit" ## to see what the commit will do first

Pushing to remote repository (e.g., github.umn.edu)

The above has only created a repo on your local computer. To push changes to a remote repository, you first go to that remote repository using your web browser and create a new repo, but don't add anything to it at that time. Then go back to the command line and add a remote repository as follows, and push to it.

git remote add origin https://github.umn.edu/<user>/cotwins.git
git push -u origin master

Bam! You've just pushed your local repo to the online repo.

The super usefulness of .gitignore

Within the root directory of your repository you can create a text file named '.gitignore'. In this file you can select which file types you DON'T WANT stored in your repository, the files you want git to ignore. Some of the data with which we work is sensitive, and you don't want a copy of that sensitive data in a repository that others can see, or which you plan to release publicly! Or perhaps you don't want to clutter your remote repository on github.umn.edu with unnecessary temporary or backup files. Here's an example .gitignore file.

# History files
*.Rhistory
*.Rapp.history
# all SSL certs
*.pem
# data files
*.tsv
*.rds
*.csv
*.dat
# Session Data files
*.RData
# Environment variable files
*.env
# Temp files
*~

Branching and merging

Branches

So, you're thinking about using git to collaborate on a bit of software development. Then start thinking about bran