A brief information about Git - bounswe/bounswe2022group1 GitHub Wiki

What is Git

Git is a free and open source distributed version control system that facilitates software development. Version control systems allow users to track the changes in the collection of files and enable multiple developers to work together on non-linear development. In software development, in practice, they are used to keep track of the changes in the source codes.

What is GitHub

GitHub is a cloud-based service that hosts project code and structure as well as track and control changes to projects' code. GitHub makes controlling codes and project development a lot easier for developers to use Git for version control and collaboration. GitHub helps developer work together on a project from any location while facilitating collaboration. GitHub is a user-friendly git repositories. Thus, anyone use GitHub to do things a developer can do with git commands via the interface.

Why are Version Control Systems useful?

It enables the user to keep track of the changes made in the files with their respective reasons. While using VSCs properly, at each snapshot, the changes on the files should be explained. This facilitates following the software development cycle vastly and in case of a problem, change in the design etc, one may always return to the previous snapshots. Moreover, one may follow multiple development branches. That eases the software development and reduces the complexity. Also, while collaborating with other people, such methods help resolving conflicts in the files.

Git is the de-facto version control system, albeit there are other version control systems but with less common use.

Basic Commands 6(https://github.com/joshnh/Git-Commands)

The standard way of using git is the command line interface. Below, we list some most widely used git commands:

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.extension] 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.extension] 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.extension] 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

Resources:

  1. The Missing Semester of Your CS Education
  2. Atlassian Tutorial
  3. Git Book
  4. ohshitgit
  5. Common Git Commands
  6. Git Commands