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
Create a new Git repository
Go to the folder of the project.
Clone an existing Git repository
Cloning is the process of pulling down a copy of a repository stored on a server.
Go to the parent folder of where you want to repository’s folder to be in.
git clone [url to repository's git file] [name of folder / repository you want]
Check the status of a Git repository
Tell Git to track a file named
git add README.md
Tell Git to track a whole folder named
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
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
Switch to the branch you want to pull changes into:
git checkout master
Pull changes from another branch into your branch:
git merge new_ux
Set a remote Github repository
Go to GitHub.com and create a new repository.
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
-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 unstagged changes to files
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>
To be even more precise, it’s a central repository with a series of local repositories.↩