Be the Best at What Matters Most in Versioning Control

Be the Best at What Matters Most in Versioning Control

Motivation

I began to work on some shared repositories with three novice students of R and Github workflow. I’ve noticed they are very enthusiasts with R/Rstudio coding, but they simply don’t have much waist play of versioning control tools.

When I was learning and aspiring to move my repositories from a centralized system called Subversion (SVN) to Github (Git)–a system that allows multiple repositories–,1 I found myself reading several guides on Internet, including those graphical ones, hoping to memorizing every Git command line trick.

In a decade or less, Git has surpassed others code management systems and became the new norm.2 That’s why learning it is relevant. However, I’ve realized that for 99% of the work I actually do, I’d have needed to get hang of only very few commands. So I decide to write them down as they may be helpful to others as well.

Find the version of Git

Run git --version

Create a new Git repository

  1. Go to the folder of the project.

  2. Run git init

Clone an existing Git repository

Cloning is the process of pulling down a copy of a repository stored on a server.

  1. Go to the parent folder of where you want to repository’s folder to be in.

  2. git clone [url to repository's git file] [name of folder / repository you want]

Check the status of a Git repository

git status

Tell Git to track a file named README.md

git add README.md

Tell Git to track a whole folder named script

git add scripts/

Tell Git to track (and stage) all files and subfolders in a directory

git add -A

Make a commit

git commit --m "my changes commit"

View all branches

git branch

Create a new branch

git branch new_model

Switch to a branch

git checkout new_model

Create a new branch and switch to it

git checkout -b new_ux

Merge one branch into another

  1. Switch to the branch you want to pull changes into: git checkout master

  2. Pull changes from another branch into your branch: git merge new_ux

Set a remote Github repository

  1. Go to GitHub.com and create a new repository.

  2. Set that repository’s url as the origin repo: git remote add origin https://github.com/danielmarcelino/myfiles.git

Push master branch to a Github repository

The -u sets the origin as the default for this branch

git push -u origin master

Pull down from branch from GitHub repository to local repository

git pull origin master

Pull down all branches from GitHub

git fetch origin

View all remote branches

git branch --remote

View log

git log

View unstagged changes to files

git diff

Unstage a file

git reset filename

Undo last commit, move commits changes to staging

git reset --soft HEAD^

Undo last commit, remove all changes in your working directory

git reset --hard HEAD^

Clone a remote repository locally

git clone url

Show changes from a particular commit

git show --pretty="format:" <commit ID>

Revert a commit by creating a new commit with opposite changes

git revert <commit ID>


  1. To be even more precise, it’s a central repository with a series of local repositories.

  2. https://www.slideshare.net/IanSkerrett/eclipse-community-survey-2014