Git Research - bounswe/bounswe2022group4 GitHub Wiki

Introduction to Version Control

Version control systems(VCS) help project contributors track the alterations made to the code and communicate with each other effectively, which makes it much easier to put new ideas into action while preserving the currently working code. There are two types of version control: centralized and distributed. The main distinction between them is that centralized VCSs keep the development history on a central server. That means everyone sharing the server also shares everyone’s work. On the other hand, on a distributed VCS, each collaborator has a local clone of the project's history. There isn’t a central entity responsible for the project's history, and each clone is a full backup of all the data. Git is a distributed type of version control system.


Git

Git is free, distributed, and open-source software that was originally authored by Linus Torvalds in 2005. One of the striking aspects of Git that makes it differ from most other version control systems is the way it thinks of its data. Git basically takes "snapshots" of all the files and stores a reference to the snapshot every time collaborators commit. Git doesn't store the files that have not changed again for the sake of efficiency. It only stores a reference to the current identical file it has already stored. In this way, all the development history is more like a flow of snapshots from the perspective of Git.


GitHub

GitHub is a hosting service site for Git. It provides a web interface to Git repositories and management tools while enabling efficient social coding. It comes with its own features along with the source code management functionality of Git. For instance, every repository on GitHub is equipped with a section for documentation, called wiki, to share detailed content about projects. With Wiki and many other features, GitHub is the most popular platform for the storage of development projects.


Definitions[1]

  • Version Control System (VCS): a program that tracks changes to specified files over time and maintains a library of all past versions of those files
  • Git: a version control system
  • repository (repo): folder containing all tracked files as well as the version control history
  • commit: a snapshot of changes made to the staged file(s); to save a snapshot of changes made to the staged file(s)
  • stage: the staging area holds the files to be included in the next commit; to mark a file to be included in the next commit
  • track: a tracked file is one that is recognized by the Git repository
  • branch: a parallel version of the files in a repository
  • local: the version of your repository that is stored on your personal computer
  • remote: the version of your repository that is stored on a remote server; for instance, on GitHub
  • clone: to create a local copy of a remote repository on your personal computer
  • fork: a copy of another user’s repository on GitHub; to copy a repository; for instance, from one user’s GitHub account to your own
  • merge: to update files by incorporating the changes introduced in new commits
  • pull: to retrieve commits from a remote repository and merge them into a local repository
  • push: to send commits from a local repository to a remote repository
  • pull request: a message sent by one GitHub user to merge the commits in their remote repository into another user’s remote repository
  • origin: a shorthand name for the remote repository that a project was originally cloned from. More precisely, it is used instead of that original repository's URL - and thereby makes referencing much easier.

Basic Commands[2]

Creating & Getting Repositories

Command Description
git init Initialize a local Git repository
git clone [url of repo] Create a local copy of a remote repository

Snapshotting

Command Description
git status List the changes that Git sees at a particular time
git add [file-name.txt] Add a file to the staging area
git add -A or . Add all new and changed files to the staging area
git commit -m "[commit message]" Once your changes are staged, save those changes into the Git repository
git rm -r [file-name.txt] Remove a file (or folder)

Branching & Merging

Command Description
git branch List branches (the asterisk denotes the current branch)
git branch -a List all branches (local and remote)
git branch [branch name] Create a new branch
git branch -d [branch name] Delete a branch
git branch -m [old branch name] [new branch name] Rename a local branch
git push origin --delete [branch name] Delete a remote branch
git checkout -b [branch name] Create a new branch and switch to it
git checkout -b [branch name] origin/[branch name] Clone a remote branch and switch to it
git checkout [branch name] Switch to a branch
git checkout - Switch to the branch last checked out
git checkout -- [file-name.txt] Discard changes to a file
git merge [branch name] Merge a branch into the active branch
git merge [source branch] [target branch] Merge a branch into a target branch

Pushing & Pulling

Command Description
git push origin [branch name] Push a branch to your remote repository
git push -u origin [branch name] Push changes to remote repository (and remember the branch)
git push Push changes to remote repository (remembered branch)
git push origin --delete [branch name] Delete a remote branch
git pull Update local repository to the newest commit
git pull origin [branch name] Pull changes from remote repository

Inspecting & Comparing

Command Description
git log View changes
git log --summary View changes (detailed)
git log --oneline View changes (briefly)
git diff [source branch] [target branch] Preview changes before merging

References

  1. Blischak, John & Davenport, Emily & Wilson, Greg. (2016). A Quick Introduction to Version Control with Git and GitHub. PLoS computational biology. 12. e1004668. 10.1371/journal.pcbi.1004668.
  2. https://github.com/joshnh/Git-Commands
⚠️ **GitHub.com Fallback** ⚠️