Giter Site home page Giter Site logo

git-cheatsheet-'s Introduction

git-cheatsheet-

Cheatsheet for git

Index

  1. Basics
  2. Github
  3. Branches

Basics

Download

https://git-scm.com/downloads

Configuration settings

settings level:

  • system -> all users
  • global -> all repositories of the current user
  • local -> current repository (default)

Set name: git config --global user.name "<your name>"
Set email: git config --global user.email <your_email>

Set editor: VS code git config --global core.editor "code --wait" # git will wait for VS code to be closed before to allow a new command
Edit all settings: git config --global -e
List config: git config --global --list
Set end of lines Mac/Linux: git config --global core.autocrlf input Set end of lines Windows: git config --global core.autocrlf true

New project

Initialisation: git init

Initialisation + add repository: git init <repository_name>

Recommanded installations:

  • Zsh with git pluging (Mac)
  • posh-git (Windows)

Manage files

Index file: git add <file_path>

Index all files: git add .

Remove from index: git restore --staged <file_paths> or (old) git reset HEAD <file_paths>

Remove all changes: git restore <file_paths> or (old) git checkout <file_paths> also add origin/master optionnal argument

Info / details

Check status: git status

List commit: git log --oneline option

Show changes: git diff

Show also index changes: git diff --cached

Show specific commit git show <commit_SHA-1>

Show master commit git show master

Show history within file (from line 10 to line 20) git blame -L 10,20 <file_name> ou -L 10

Commit

Add to local repository: git commit -m "<commit_message>"

Add to local repository keep same commit: git commit --amend"

Tag definition

tag master last commit of master branch

tag head current commit on which we are

tag origin/master last commit of the remote repository

Move

Move to commit git checkout <commit_SHA-1>

Move to master git checkout master

Move to tag git checkout <tag_name>

When HEAD points to a commit (not a branch) state is 'detached HEAD'

Custom tags

Custom tags are linked to one commit

Create tag git tag <tag_name>

Other option git tag <tag_name> -m"<tag_message>"

Delete tag git tag --delete <tag_name>

List tags git tag

Copy a commit

Copy commit: git cherry-pick <commit_SHA-1>

Github

Clone git repository from github (remote origin created automatically) git clone <repository_url> <new_folder_name>

List remotes: git remote -v

Show remote details: git remote show <remote_name>

Add remote: git remote add <remote_name> <repository_url>

Push commits: git push -u <remote_name> <branch_name> example git push -u origin master <remote_name> is optionnal defaul is origin

Push tag: git push <remote_name> <tag_name>

Push all tags: git push <remote_name> --tags

Fetch changes git fetch get the commits + tags + moves tag origin/master

Pull changes git pull perform git fetch + moves tag master

use .gitignore example

tmp/todo.txt
tmp/*
*.txt

Temporay change

Cut current changes git stash

Paste changes git stash pop

Cut and save current changes git stash save "<stash_message>"

Paste saved changes git stash pop <stash_index>

List changes git stash list

Details change git stash show <stash_index>

Merge commit

Commist list (remote repository) : A-B-C-D-E Commits list (local repository) : A-B-C-D-F

Does not working : git push Must update local repository

NOT RECOMMANDED Update local repository start merge automatically : git pull If conflit, manage conflicts in file then: git add . Create merge commit: git commit -m "merge of files" Push changes: git push

RECOMMANDED Update local repository : git pull --rebase If conflit, manage conflicts in file then: git add . + git rebase --continue Push changes: git push

Branches

Merge branch

Master branch: A-B-C-D-E Feature branch (branch_name): A-B-C-D-1-2-3

NOT RECOMMANDED Move to master : git switch master or (old) git checkout master Start merge: git merge <branch_name> If conflit, manage conflicts in file then: git add . + git commit -m "merge of files" Push changes: git push

RECOMMANDED Move to feature branch : git switch <branch_name> or (old) git checkout <branch_name> Update local repository : git rebase master While conflit, manage conflicts in files then: git add . + git rebase --continue Move to master : git switch master or (old) git checkout master Start merge: git merge <branch_name>

List branches: git branch List branches on remote repository: git branch -a

Create new branche: git branch <branch_name>

Move branche: git switch <branch_name> or git checkout <branch_name>

Create + move to branche: git switch -c <branch_name> or git checkout -b <branch_name>

Logs in branch: git log <branch_name>

Delete branch

Delete branch locally: git branch -d <branch_name>

Delete branch on remote repository: git push origin --delete <branch_name>

big code

git-cheatsheet-'s People

Contributors

remember-the-future avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.