Git: Terminology 101
*Commit
A commit is a collection of changes. Whenever you make a commit you must tell Git to save all of the changes that you have made.
*Branch
A branch is just a sequence of commits or a pointer to a commit.
*Merge
Merge means join two or more development histories together.
*Master
The default branch name in Git is master.
*HEAD
It is a pointer to the most recent commit on the current branch.
*Workspace
It is the colloquial name for your local copy of a Git repository.
*Origin
It means the default name for a remote repository.
* Clone
Clone operation copies remote repository into local.
* Local repository
It stands for where you keep your copy of a Git repository on your workstation.
*Remote repository
It is a secondary copy of a Git repository where you push changes for collaboration or backup.
* Upstream repository
It refers to the colloquial term for a remote repository that you track.
* Pull request
Pull Requests are commonly used by teams and organizations collaborating using the Shared Repository Model, where everyone shares a single repository and topic branches are used to develop features and isolate changes.
*Merge request
Merge requests allow you to visualize and collaborate on the proposed changes to source code that exist as commits on a given Git branch.
*Checkout
A checkout is the act of switching between different versions of a target entity.
*origin/master
It is the default setting for a remote repository and its primary branch.
*Gitignore file
The .gitignore file is a text file that tells Git which files or folders to ignore in a project.
*Postscript
Puns are one of the best parts of Git. Have fun with them.
* Tagging
A tag represents a version of a particular branch at a moment in time.
*Push
Push operation pushes local commits to remote repository.
*Pull
Pull is opposite of Push operation.
*Fetch
Fetch just “downloads” the changes from the remote to your local repository.
Getting & Creating Projects
- git config
git config –global user.name [name]
git config –global user.email [email address]
This command sets the author name and email address respectively to be used with your commits.
- git init — Initialize a local Git repository
- git
clone ssh://git@github.com/[username]/[repository-name].git
Create a local copy of a remote repository
Basic Snapshotting
- git status — To see what edits you’ve made since the last commit
- git add [file-name.txt] — Add a file to the staging area
- git add -A — Add all new and changed files to the staging area
- git commit -m “[commit message]” — Commit changes
- git rm -r [file-name.txt] — Remove a file (or folder)
Branching & Merging
- git branch — lists all the local branches in the current repository
- 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 push origin — delete [branch name] — Delete a remote branch
- git checkout -b [branch name] — Create a new branch and switch to it
- git checkout [branch name] — Switch to a branch
- git checkout — [file-name.txt] — Discard changes to a file
- git merge [branch name] — Merge a branch into the active branch
- git stash — Stash changes in a dirty working directory
- git stash clear — Remove all stashed entries
Sharing & Updating Projects
- 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
- git remote add origin ssh://git@github.com/[username]/[repository-name].git — -Add a remote repository
- git remote set-url origin ssh://git@github.com/[username]/[repository-name].git — Set a repository’s origin branch to SSH
Inspection & Comparison
- 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