Create an empty Git repository or reinitialize an existing one.
$ git init
Clone a repository into a new directory, including all of the files, branches and commits.
$ git clone <repository_url>
Link the local repository to an empty GitHub repository.
$ git remote add origin <repository_url>
Set a Username
$ git config --global user.name "<firstname lastname>"
Set an Email Address
$ git config --global user.email "<valid@email.com>"
How can I save username and password in Git?
Attention: This method saves the credentials in plaintext
on your PCβs disk. Everyone on your computer can access it.
git config --global credential.helper store
After entering the command, just do a git pull
or git push
request and enter your credentials. After that you will not be asked to do it again.
Check the current branch.
$ git branch
Create a new branch.
$ git branch <branch_name>
Switch branches or restore working tree files.
$ git checkout -b <branch_name>
Delete a branch.
$ git branch -d <branch_name>
Show the working tree status.
$ git status
Add file contents to the index, to prepare the content staged for the next commit.
$ git add <file_name>
Add all changed files in your present working directory to the index.
$ git add .
Record changes to the repository. Create a new commit containing the current contents of the index and the given log message describing the changes.
$ git commit -m "<descriptive message>"
Incorporates changes from a remote repository into the current branch.
$ git pull origin <branch_name>
Updates remote refs using local refs, while sending objects necessary to complete the given refs.
git push origin <branch_name>
Synchronize your local repository with the remote repository on GitHub.
$ git fetch
Join two or more development histories together.
$ git merge <branch_name>
Reset current HEAD to the specified state, but leave the working directory unchanged.
$ git reset
Reset current HEAD to match most recent commit and overwrites all changes in the working directory.
$ git reset --hard
Revert some existing commits.
git revert <commit>
Git usages that are a bad practice and you should avoid.
- Do not commit directly to the main, release or dev branches.
- Donβt commit files that contain the individual user environment variables (aka. .env/.env.* files).
- Avoid working on multiple issues in the same branch.
- NEVER do a force push.
- Do not edit or delete the last commited message.