- Git (Terminal)
- Introduction to Git
- Initializing a repository
- Cloning a repository
.gitignore
- Checking the status
- Staging files
- Unstaging files
- Commiting files
- Checkout
- View differences
- Checking history
- Branches
Git is a distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Think of a repository as a project folder. It contains information about itself, any remote repositories, its branches, commits and changes.
All of the information about the repository is saved in the .git
subdirectory.
Working changes
Otherwise known as "unstaged", these are changes that are not stored in other places.
Staged changes
Unlike unstaged changes, these changes are stored locally, and can be thought as an intermediary between unstaged changes and commits.
Commits
Commits are the real deal, they store changes in their respective branch, they contain information about what changes they hold and which commits come before them. They can be pushed to remote repositories, like GitHub.
Before you use any commands: Replace any names within square brackets with their corresponding names.
Do not write the $
in your terminal, they indicate a start of a new command, the rest indicates console output.
The
git init
command creates an empty Git repository - basically a .git
directory with its corresponding subdirectories.
$ git init Initialised empty Git repository in /path/to/repository/.git/If you run this command in an existing repository, it will not overwrite any files:
$ git init Reinitialised existing Git repository in /path/to/repository/.git/
$ git add [file]I'd recommend using
.
as the file, as it includes everything.
You can also use the -v
flag, because it outputs what has been staged.
$ git add . -v add 'src/main/java/com/example/AddedFile.java' remove 'src/main/java/com/example/RemovedFile.java'
This command will list all branches.
Existing branches are listed, and the current branch will be highlighted in green and marked with an asterisk.
The
-r
option causes the remote-tracking branches to be listed.The
-a
option shows both local and remote branches.
$ git branch dev * master stable $ git branch -a dev * master stable remotes/origin/dev remotes/origin/master remotes/origin/stable
$ git branch [branch]
$ git branch -m [old branch] [new branch]
$ git branch -m [old branch] [new branch]Go to: Checkout
$ git merge [branch]