Initialize an existing directory as a Git repository
$ git init
$ git init --initial-branch=main # define the initial branch name
$ git init -b=main # short version
Git: master all secrets
Makes a duplicate of an existing Git repository. Cloning is the most popular method through which developers receive a working copy of a central repository.
$ git clone <url>
$ git clone <url> <repo_name>
Git: master all secrets
Add a git URL as an alias
git remote add <alias> <url>
Git: master all secrets
It tells Git that you want to include updates to all your files in the next commit.
git add .
Git: master all secrets
Add a file as it looks now to your next commit
git add <file>
Git: master all secrets
Create a new commit containing the current contents of the index and the given log message describing the changes.
git commit -m "description"
Git: master all secrets
It moves all your committed changes to the remote repository.
git push
Git: master all secrets
Transmit local branch commits to the remote repository branch
git push <alias> <branch>
Git: master all secrets
Push all of your local branches to the specified remote
git push --all
git push <remote> --all
Git: master all secrets
Tags are not automatically pushed when you push a branch or use the --all option. The --tags flag sends all of your local tags to the remote repository.
git push --tags
git push <remote> --tags
Git: master all secrets
Displays the current status of the working directory. You should use it in combination with git add and git commit to know what files were added and committed.
git status
Git: master all secrets
List your branches. a * will appear next to the currently active branch
git branch
Git: master all secrets
Create a new branch at the current commit
git branch <branch_name>
Git: master all secrets
Create a new branch at the current commit
git branch -M main
Git: master all secrets
Creates a new branch on your local machine and opens it.
git checkout -b <new_branch_name>
Git: master all secrets
Delete a branch on your local filesystem.
git branch -d <branch_name>
Note: I always delete branches locally through this command and use GitHub UI to delete them globally. Seems for me like the safest method.
Git: master all secrets
Delete a branch on remote.
git branch -D <branch_name>
Git: master all secrets
Integrate all changes from another branch into yours.
git merge <branch_name>
Git: master all secrets
By calling it, you will get all changes from the remote branch to your local copy.
git pull
Git: master all secrets
Fetch down all the branches from that Git remote
git fetch
git fetch <remote>
git fetch <remote> <branch>
git fetch --all # fetches all branches of all remotes
git fetch --dry-run
The --dry-run option will perform a demo run of the command. It will output examples of actions it will take during the fetch but not apply them.
Git: master all secrets
Stores uncommitted changes (both staged and unstaged) for later use and subsequently reverts them from your working copy.
git stash
You aren't limited to a single stash
Git: master all secrets
List stashes
$ git stash list
stash@{0}: WIP on main: 5002d47 our new homepage
stash@{1}: WIP on main: 5002d74 our new contact page
stash@{2}: WIP on main: 5002d88 our new support page
Git: master all secrets
Reapply previously stashed changes
git stash pop
Choose which stash to re-apply
git stash pop stash@{2}
Git: master all secrets
Discard the changes from top of stash stack
git stash drop
Git: master all secrets
Show all commits in the current branch’s history
git log
Limit the number of commits that are displayed
git log -3
Git: master all secrets
Show all commits in the current branch’s history and display message in one line.