section
qa
answer
Git Glossary
Branch
Branches represent specific versions of a repository that 'branch out' from your main project. Branches allow you to keep track of experimental changes you make to repositories and revert to older versions.
Git Glossary
Commit
A commit represents a specific point in your project's history. Use the commit command in conjunction with the git add command to let git know which changes you wish to save to the local repository. Note that commits are not automatically sent to the remote server.
Git Glossary
Checkout
Use the git checkout command to switch between branches. Just enter git checkout followed by the name of the branch you wish to move to, or enter git checkout master to return to the master branch. Mind your commits as you switch between branches.
Git Glossary
Fetch
The git fetch command copies and downloads all of a branch's files to your device. Use it to save the latest changes to your repositories. It's possible to fetch multiple branches simultaneously.
Git Glossary
Fork
A fork is a copy of a repository. Take advantage of 'forking' to experiment with changes without affecting your main project.
Git Glossary
Head
The commit at the tip of a branch is called the head. It represents the most current commit of the repository you're currently working in.
Git Glossary
Index
Whenever you add, delete or alter a file, it remains in the index until you are ready to commit the changes. Think of it as the staging area for Git. Use the git status command to see the contents of your index. Changes highlighted in green are ready to be committed while those in red still need to be added to staging.
Git Glossary
Master
The master is the primary branch of all your repositories. It should include the most recent changes and commits.
Git Glossary
Merge
Use the git merge command in conjunction with pull requests to add changes from one branch to another.
Git Glossary
Origin
The origin refers to the default version of a repository. Origin also serves as a system alias for communicating with the master branch. Use the command git push origin master to push local changes to the master branch.
Git Glossary
Pull
Pull requests represent suggestions for changes to the master branch. If you're working with a team, you can create pull requests to tell the repository maintainer to review the changes and merge them upstream. The git pull command is used to add changes to the master branch.
Git Glossary
Push
The git push command is used to update remote branches with the latest changes you've committed.
Git Glossary
Rebase
The git rebase command lets you split, move or get rid of commits. It can also be used to combine two divergent branches.
Git Glossary
Remote
A remote is a clone of a branch. Remotes communicate upstream with their origin branch and other remotes within the repository.
Git Glossary
Repository
Git repositories hold all of your project's files including branches, tags and commits.
Git Glossary
Stash
The git stash command removes changes from your index and 'stashes' them away for later. It's useful if you wish to pause what you're doing and work on something else for a while. You can't stash more than one set of changes at a time.
Git Glossary
Tags
Tags provide a way to keep track of important commits. Lightweight tags simply serve as pointers while annotated tags get stored as full objects.
Git Glossary
Upstream
In the context of Git, upstream refers to where you push your changes, which is typically the master branch.
Commands for Configuring Git
Set the username
git config --global user.name
Commands for Configuring Git
Set the user email
git config --global user.email
Commands for Configuring Git
Create a Git command shortcut
git config --global alias.
Commands for Configuring Git
Set the preferred text editor
git config --system core.editor
Commands for Configuring Git
Open and edit the global configuration file in the text editor
git config --global --edit
Commands for Configuring Git
Enable command line highlighting
git config --global color.ui auto
Commands for Setting Up Git Repositories
Create an empty repository in the project folder
git init
Commands for Setting Up Git Repositories
Clone a repository from GitHub and add it to the project folder
git clone (repo URL)
Commands for Setting Up Git Repositories
Clone a repository to a specific folder
git clone (repo URL) (folder)
Commands for Setting Up Git Repositories
Display a list of remote repositories with URLs
git remote -v
Commands for Setting Up Git Repositories
Remove a remote repository
git remote rm (remote repo name)
Commands for Setting Up Git Repositories
Retrieve the most recent changes from origin but don't merge
git fetch
Commands for Setting Up Git Repositories
Retrieve the most recent changes from origin and merge
git pull
Commands for Managing File Changes
Add file changes to staging
git add (file name)
Commands for Managing File Changes
Add all directory changes to staging
git add .
Commands for Managing File Changes
Add new and modified files to staging
git add -A
Commands for Managing File Changes
Remove a file and stop tracking it
git rm (file_name)
Commands for Managing File Changes
Untrack the current file
git rm --cached (file_name)
Commands for Managing File Changes
Recover a deleted file and prepare it for commit
git checkout
Commands for Managing File Changes
Display the status of modified files
git status
Commands for Managing File Changes
Display a list of ignored files
git ls-files --other --ignored --exclude-standard
Commands for Managing File Changes
Display all unstaged changes in the index and the current directory
git diff
Commands for Managing File Changes
Display differences between files in staging and the most recent versions
git diff --staged
Commands for Managing File Changes
Display changes in a file compared to the most recent commit
git diff (file_name)
Commands for Declaring Git Commits
Commit changes along with a custom message
git commit -m '(message)'
Commands for Declaring Git Commits
Commit and add all changes to staging
git commit -am '(message)'
Commands for Declaring Git Commits
Switch to a commit in the current branch
git checkout
Commands for Declaring Git Commits
Show metadata and content changes of a commit
git show
Commands for Declaring Git Commits
Discard all changes to a commit
git reset --hard
Commands for Declaring Git Commits
Discard all local changes in the directory
git reset --hard Head
Commands for Declaring Git Commits
Show the history of changes
git log
Commands for Declaring Git Commits
Stash all modified files
git stash
Commands for Declaring Git Commits
Retrieve stashed files
git stash pop
Commands for Declaring Git Commits
Empty stash
git stash drop
Commands for Declaring Git Commits
Define a tag
git tag (tag_name)
Commands for Declaring Git Commits
Push changes to origin
git push
Commands for Git Branching
Display a list of all branches
git branch
Commands for Git Branching
Make a new branch and switch to it
git checkout -b
Commands for Git Branching
Switch to a branch
git checkout
Commands for Git Branching
Delete a branch
git branch -d
Commands for Git Branching
Merge a different branch with your active branch
git merge
Commands for Git Branching
Fetch a branch from the repository
git fetch remote
Commands for Git Branching
View merge conflicts between branches
git diff
Commands for Git Branching
Preview changes before merging branches
git diff
Commands for Git Branching
Push all local branches to a designated remote repository
git push --all
Commands for Declaring Git Commits
How to undo commit?
git revert
Commands for Managing File Changes
How can I know if a branch has been already merged into master?
git branch --merged master (By default this applies to only the local branches. The -a flag will show both local and remote branches, and the -r flag shows only the remote branches.)
Commands for Managing File Changes
How can I know if a branch has been not merged into master?
git branch --no-merged (By default this applies to only the local branches. The -a flag will show both local and remote branches, and the -r flag shows only the remote branches.)
Commands for Managing File Changes
How to cleaning up remote branches
git branch -r | xargs -t -n 1 git branch -r --contains
FAQ
How do I ignore an error on 'git pull' about my local changes would be overwritten by merge?
git stash save --keep-index
FAQ
If you don't need stash, what should I do?
git stash drop
FAQ
Show only file names from the previous commit
git show --pretty='' --name-only ad61a8bfae
FAQ
How to move to the previous push (hard)
git reset --hard b4a5191e