Skip to content

πšƒπš‘πšŽ πš„πš•πšπš’πš–πšŠπšπšŽ π™Άπš’πš π™²πš‘πšŽπšŠπšπšœπš‘πšŽπšŽπš

Notifications You must be signed in to change notification settings

IuraCPersonal/git-cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 

Repository files navigation

The Ultimate Git Cheatsheet

DOWNLOAD AND CREATE PROJECTS

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>

SETUP ACCOUNT

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.

BRANCHES

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>

BASIC SNAPSHOTTING

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

MERGING

Join two or more development histories together.

$ git merge <branch_name>

REDO COMMITS

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>

GITHUB REPOS EVERY DEVELOPER MUST KNOW

HOW NOT TO USE GIT

Git usages that are a bad practice and you should avoid.

  1. Do not commit directly to the main, release or dev branches.
  2. Don’t commit files that contain the individual user environment variables (aka. .env/.env.* files).
  3. Avoid working on multiple issues in the same branch.
  4. NEVER do a force push.
  5. Do not edit or delete the last commited message.

About

πšƒπš‘πšŽ πš„πš•πšπš’πš–πšŠπšπšŽ π™Άπš’πš π™²πš‘πšŽπšŠπšπšœπš‘πšŽπšŽπš

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published