Git Version Control System - koglak/SWE573 GitHub Wiki

1. Git Version Control System

1.1. What is Git?

Git is a widely used version control system. It is open source and free system. Famous creator of Linux operating system, Linus Torvalds, had created git in 2005. Enormous number of projects are based on git, including commercial and open source projects. Moreover, git is compatible with many operating system, as well as, IDEs. This is why, git is large-scale preferred system. In addition that, performance of git is high when it is compared to other alternatives [1].

Git repositories include all files of preject and revision history. Therefore, it is used to track changes in the code[2].

  • Helps to save history of project,
  • Allows to work on same project collobratively,
  • Allows to use it offline,
  • Allows to track changes in source code,
  • Supports non-linear development
  • Provides ease-of-use for branching.

Git Version Control

1.2. What is Branching?

Branching is a feature in git. Before edition in code is not ready, git creates a branch which is apart from master branch. After developer committed the edition, git merges master branch and editted branch together[3].

Branching

1.3. Git Commands [4]

Here is the mostly used git commands as cheat sheet.

1.3.1. Setup

The git config command sets configuration values for your Git installation. git config directly writes to local level by default without configuration option. --local config values are stored in repo's .git directory. --global config values are stored in the user's home directory. --system config values are applied to entire machine, which covers all users on an OS and all repos[5].

Command Description
git config --global user.name “[firstname lastname]” Set a name to identify person
git config --global user.email “[valid-email]” Set a e-mail address to associate with person

1.3.2. Setup & Init

git init command creates new Git repository, as well as, converts an existing project to git repository. This is usually first command to run. It initialize git configuration under .git sub-directory file. git clone is depended on git init command. Because, git clone is used to copy/clone an existing repo at in a new directory, at another location[6].

Command Description
git init creates new directory as a Git repository
git init <directory> initialize an existing directory as a Git repository
git clone [url] Revoke all repository from a hosted location via URL

1.3.3. Stage & Snapshot

git diff command shows the differences between files in two commits or between a commit and your current repository. Before git commit, files which will be committed should be determined for git system. In this case, git add command is used to put those files in stage area. Later on, git commit is used to capture the state of project. If a file accidently is staged, git reset is used to unstage that file. git status is used to display state of repo and staging area. Therefore, you can see the tracked, untracked files and changes. The command will not display any commit records or information[7].

Command Description
git status show modified files in working directory
git add [file] add a file for next commit (stage)
git reset [file] unstage a file while retaining the changes in working directory
git diff diff of what is changed but not staged
git diff --staged diff of what is staged but not yet commited
git commit -m “[descriptive message]” commit your staged content as a new commit snapshot

1.3.4. Branch & Merge

git branch command allows to create, list, rename and delete branches. It does not allow to switch between branches. When a new feature is under development, new branch is created by using git branch new_branch. Once it is created, git checkout new_branch command is used to swith new branch. Mostly, git merge is used to combine two branches[8].

Command Description
git branch list your branches
git branch [branch-name] create a new branch at the current commit
git checkout switch to another branch and check it out into your working director
git merge [branch] merge the specified branch’s history into the current one
git log show all commits in the current branch’s history

1.3.5. Other Widely Used Git Commands

Command Type Command Description
Inspect & Compare git log show the commit history for the currently active branch
Inspect & Compare git log branchB..branchA show the commits on branchA that are not on branchB
Inspect & Compare git diff branchB...branchA show the diff of what is in branchA that is not in branchB
Track Path Changes git rm [file] delete the file from project and stage the removal for commit
Rewrite History git rebase [branch] apply any commits of current branch ahead of specified one
Rewrite History git reset --hard [commit] clear staging area, rewrite working tree from specified commit
Temporary Commits git stash Save modified and staged changes
Temporary Commits git stash list list stack-order of stashed file changes
Temporary Commits git stash pop write working from top of stash stack
Temporary Commits git stash drop discard the changes from top of stash stack

OTHER COMMANDS

The git remote command lets you create, view, and delete connections to other repositories. List the remote connections you have to other repositories.

`git remote`

Create a new connection to a remote repository.

`git remote add <name> <url>`

Remove the connection to the remote repository called <name>.

`git remote rm <name>`

Rename a remote connection from <old-name> to <new-name>.

`git remote rename <old-name> <new-name>`

The git push command is used to write to a remote repository.

`git push <remote-name> <branch-name>`

REFERENCES

[1] Git Tutorial

[2] What is Git: Features, Command and Workflow in Git

[3] Git Branch

[4] Git Cheat Sheet

[5] Git Commit & Stage

[6] Git Init

[7] Stage & Commit

[8] Branch & Merge

⚠️ **GitHub.com Fallback** ⚠️