{"id":18809482,"url":"https://github.com/resourcepool/training-git-cheatsheet","last_synced_at":"2026-01-31T13:43:25.701Z","repository":{"id":16274604,"uuid":"19022951","full_name":"resourcepool/training-git-cheatsheet","owner":"resourcepool","description":"Cheatsheet for git commands","archived":false,"fork":false,"pushed_at":"2016-06-24T12:55:13.000Z","size":8,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-29T22:47:01.678Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/resourcepool.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-22T08:49:41.000Z","updated_at":"2021-05-10T11:55:40.000Z","dependencies_parsed_at":"2022-07-25T04:02:05.989Z","dependency_job_id":null,"html_url":"https://github.com/resourcepool/training-git-cheatsheet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/resourcepool%2Ftraining-git-cheatsheet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/resourcepool%2Ftraining-git-cheatsheet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/resourcepool%2Ftraining-git-cheatsheet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/resourcepool%2Ftraining-git-cheatsheet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/resourcepool","download_url":"https://codeload.github.com/resourcepool/training-git-cheatsheet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239743473,"owners_count":19689502,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T23:16:32.953Z","updated_at":"2026-01-31T13:43:25.636Z","avatar_url":"https://github.com/resourcepool.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"#Git Cheatsheet  \n\n##1. Git Configuration\n###1.1. GitConfig\n\u003e`$ git config --global user.name \"your name\"`  \n\n\u003e`$ git config --global user.email \"your@email.com\"`  \n\nEdit the .gitconfig file via the command:  \n\n\u003e`$ git config --global -e`  \n\nTo activate the syntactic color and the \"tree\" alias, add the following lines to the .gitconfig: \n\u003e  [alias]  \n   tree = log --graph --decorate --pretty=oneline --abbrev-commit --all  \n  \n\u003e  [color]  \n   branch = auto  \n   diff = auto  \n   interactive = auto  \n   status = auto  \n\n###1.2. End of Line management\n**Windows** : The end of lines are modeled by a CRLF (Carriage Return Line Feed \u003c=\u003e \\r\\n)  \n**Linux** : modeled by LF (Line Feed \u003c=\u003e \\n)  \n**Git** : all is stored as LF by convention  \n\n**Windows Client** : must always process a **CRLF → LF** conversion when writing in the database, and must always process a **LF →CRLF** conversion when retrieving data from the base.\n\u003e`$ git config --global -e core.autocrlf true`\n\n**Linux Client** : must always process a **CRLF → LF** conversion when writing in the database (but not needed normaly) and does not need any conversion when retrieving data.\n\u003e`$ git config --global -e core.autocrlf input`\n\n##2. Initialization or Cloning a repository\n###2.1. Initialization of a new central repo (i.e. origin)\nFor a new project, you have to initialize a central repository on your server. From there, other clients will connect and push theirs modifications. To initialize a myrepo project:\n\u003e`$ mkdir myrepo.git`  \n\u003e`$ cd myrepo.git`  \n\u003e`$ git –-bare init`  \n\n###2.2. Initialization of a new local repo\nGo to your project root, and run the following command:\n\u003e`$ git init`\n\nIf the file has a central remote repo (i.e. remote), it has to be declared. By convention, « origin » should be the name for the main repo.  \n*N.B.: You can have any number of remote repos as git is fully distributed*  \nThe deposit could be an URI:  \n\u003e`$ git remote add origin https://github.com/me/myrepo.git`  \n\nor something else (e.g. a remote repo via ssh):  \n\u003e`$ git remote add origin git@myserver:~/git/myrepo.git`  \nor even:  \n\u003e`$ git remote add origin /home/git/myrepo.git`  \n\n###2.3. Cloning an existing repo\nIf the project already exists (i.e.: already has a remote repo), you only need to clone it:\n\u003e`$ git clone git@myserver:~/git/myrepo.git`  \n\nA myrepo folder will be created in the directory you run the command at.\n\n##3. Main Commands\n\n###3.5. Must-Have Commands  \n####Show state of the Staging area\n\u003e`git status`\n\n####Show main tree with all the branches (warning: it is an alias created with your gitconfig!)\n\u003e`git tree`\n\n####Stash your non-committed changes to temporarily switch to another branch\n\u003e`git stash`\n\n####Redo (i.e. pop) your non-committed changes when back to the branch\n\u003e`git stash pop`\n\n###3.2. Branches\n(+) Create a new branch at the actual location (\u003c=\u003e position in the tree) without selecting it:\n\u003e`$ git branch branch_name`  \n\n(+) Go on a branch and create it at the actual location if it does not exist yet:\n\u003e`$ git checkout -b branch_name`  \n\n(x) Delete a branch from the local repo:\n\u003e`$ git branch -D branch_name`\n\n(x) Delete a branch from the origin repo: (two solutions)  \n\u003e`$ git push origin --delete branch_name` (git v1.7.0+)  \nor  \n\u003e`$ git push origin :branch_name` (older versions but also works with newer)\n\n(\u003e) Push a branch to the origin repo:\n\u003e`$ git push origin localbranch:remotebranch`  \nor if both branches have the same name:  \n\u003e`$ git push origin branch .`  \nuse `-f` to force the update (WARNING: will override the remote branch with yours)  \n\u003e`$ git push origin -f branch`  \n\n(T) Create an annoted tag on a commit:\n\u003e`$ git tag -a tag_name sha_of_commit -m \"tag for version vX.X\"`  \n\n(T) Create a lightweight tag on a commit:\n\u003e`$ git tag tag_name sha_of_commit`  \n\n(\u003c) Get latest version of branches from the origin repo:\n\u003e`$ git fetch origin`  \n\n(\u003c) Get latest version of branches from the origin repo, including removed branches\n\u003e`$ git fetch -p origin`  \n\n(\u003c) Get latest version of master branch from the origin repo, and merge it into current branch\n\u003e`$ git pull origin master`  \n\n(\u003c) Get latest version of master branch from the origin repo, rebase your current branch on top of it\n\u003e`$ git pull --rebase origin master`  \n\n\n###3.3. Index\n(+) Add new files or modified files to the index: (3 examples)  \n\u003e`$ git add .`  \n\u003e\u003eadd all files of the current folder and its subfolder  \n\n\u003e`$ git add -A`\n\u003e\u003eadd all files (including deleted and modified files) to the index\n\n\u003e`$ git add file2.txt folder1/* folder2/*.txt`  \n\u003e\u003e add file2.txt, all files of folder1 folder , and all text files of folder2 folder\n\n\n(x) Remove files from the index (will be marked as unstaged or untracked files) (2 examples):\n\u003e`$ git reset HEAD`  \n\u003e\u003eremove all non-commited files from the index\n\n\u003e`$ git reset HEAD file1.txt folder1/*`  \n\u003e\u003eremove file1.txt and all files of folder1 from the index  \n\n###3.4. Commit\n(+) Commit changes added to the index:\n\u003e`$ git commit -m \"message of your commit\" .`  \n\n(+) Add other files to the index to the last commit (e.g. in case of omission), if you did not push on the remote repo yet:  \n\u003e`$ git commit --amend -m \"new message of commit which will replace the old one\"`  \n\n(x) Properly cancel a commit (will create a new commit which contains the reverted changes from the previous one):\n\u003e`$ git revert HEAD~numberOfCommitToBeCancelled`  \n\u003e\u003ee.g.: Cancel the previous commit:  \n\u003e`$ git revert HEAD~1`  \n\n###3.5. Rebase and interactive rebase\n(^) Apply commits of the remote branch which differs from the local branch:\n\u003e`$ git rebase origin/branchname`  \n\n(e) Start an interactive rebase of the 4 last commits:  \n\u003e`$ git rebase -i HEAD~3`  \n\nFor example, something like this is shown:  \n\u003epick 4995a59 my second commit  \n\u003epick 531b54f my third commit  \n\u003epick 0e9c8cc my forth commit  \n\nOne can now modifiy the content to process the following tasks:\n\n####(e) Inversing order of commits 531b54f and 0e9c8cc:  \n\u003epick 4995a59 my second commit  \n\u003epick 0e9c8cc my forth commit  \n\u003epick 531b54f my third commit  \n\n####(e) Fusionning commit 531b54f with its previous 4995a59:  \n\u003epick 4995a59 my second commit  \n\u003esquash 531b54f my third commit  \n\u003epick 0e9c8cc my forth commit  \n\n####(x) Deleting commit 531b54f:  \n\u003epick 4995a59 my second commit  \n\u003e\\#Delete this line: pick 531b54f my third commit   \n\u003epick 0e9c8cc my forth commit  \n\n####(e) Editing commit 531b54f:  \n\u003epick 4995a59 my second commit  \n\u003e**edit** 531b54f my third commit  \n\u003epick 0e9c8cc my forth commit  \n\nThen perform your modifications, commit, and execute  \n\u003e`$ git rebase --continue`  \n\n###3.6. Merge and mergetool\n(c) Configure a mergetool (e.g. replace mymt by your mergetool: meld,kdiff3,...)  \n\u003e`git config --global merge.tool mymt\"`  \n\n(m) Launch a merge of the mybranchy branch on the actual branch (mybranchx)  \n\u003e`git merge mybranchy -m \"merge of mybranchy on mybranchx\"`  \n\n\n##Bibliography\nA very easy-to-follow and complete git training\n\u003e[http://git-scm.com/book/en](http://git-scm.com/book/en)  \n\nA very complete book about git  \n\u003e[https://github.com/blog/1640-git-internals-pdf-open-sourced](https://github.com/blog/1640-git-internals-pdf-open-sourced)  \n\nA cheatsheet of the git commands (listed in layers)\n\u003e[http://ndpsoftware.com/git-cheatsheet.html](http://ndpsoftware.com/git-cheatsheet.html)\n\nA very good document to understand and wisely choose the most adapted workflow for your project\n\u003e[https://www.atlassian.com/git/workflows#!workflow-release-cycle](https://www.atlassian.com/git/workflows#!workflow-release-cycle)\n\nAn article about the use of gitflow\n\u003e[http://blogs.endjin.com/2013/04/a-step-by-step-guide-to-using-gitflow-with-teamcity-part-3-gitflow-commands](http://blogs.endjin.com/2013/04/a-step-by-step-guide-to-using-gitflow-with-teamcity-part-3-gitflow-commands/)  \n\n##Contributors\n\n@Loicortola for the CHEATSHEET redaction  \n@VinceFoixCable for the review and english translation  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fresourcepool%2Ftraining-git-cheatsheet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fresourcepool%2Ftraining-git-cheatsheet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fresourcepool%2Ftraining-git-cheatsheet/lists"}