{"id":21399649,"url":"https://github.com/natancabral/git-start","last_synced_at":"2026-05-20T09:06:43.243Z","repository":{"id":56612601,"uuid":"308107424","full_name":"natancabral/git-start","owner":"natancabral","description":"Basic Git commands. git init initializes a brand new Git repository and begins tracking an existing directory. git clone creates a local copy of a project that already exists remotely. git add stages a change. git commit saves the snapshot to the project history and completes the change-tracking process.","archived":false,"fork":false,"pushed_at":"2022-04-25T15:04:12.000Z","size":137,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-16T15:52:41.884Z","etag":null,"topics":["git","github","projects"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/natancabral.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-28T18:31:36.000Z","updated_at":"2022-01-17T12:24:53.000Z","dependencies_parsed_at":"2022-08-15T22:00:25.385Z","dependency_job_id":null,"html_url":"https://github.com/natancabral/git-start","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/natancabral/git-start","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natancabral%2Fgit-start","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natancabral%2Fgit-start/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natancabral%2Fgit-start/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natancabral%2Fgit-start/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/natancabral","download_url":"https://codeload.github.com/natancabral/git-start/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natancabral%2Fgit-start/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33253077,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-20T04:48:54.280Z","status":"ssl_error","status_checked_at":"2026-05-20T04:48:10.851Z","response_time":356,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["git","github","projects"],"created_at":"2024-11-22T15:15:55.197Z","updated_at":"2026-05-20T09:06:43.227Z","avatar_url":"https://github.com/natancabral.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Learn to use Git Terminal by example\n\nIf you are used to work with GUI tool and want to learn the basics of working using the terminal, keep on reading.\n\n## Start Project\n\n* en: Create a new project to start.\n```bash\nmkdir project-name # create folder project\ncd project-name # enter folder project\n```\n\n## Initialize Git\n\n* en: You need install GIT first. Terminal: \"sudo apt install git\".\n\n```bash\ngit init # create files git\n```\n\n**GitHub**\n\n\u003e You need login on GitHub to create a new repository (+ \u003e new repository).\n\u003e Give your repository a name--ideally the same name as your local project.\n\u003e The next screen you see will be important, so don't close it.\n\u003e Inside click on Code \u003e Clone (url)\n\n## Back Terminal\n\n* en: Create a new file.\n```bash\necho '# Title' \u003e README.md\n```\n\n* en: Now link your local project with remote project (repository):\n```bash\ngit remote add origin https://github.com/\u003cgithub_username\u003e/\u003crepository_name\u003e.git\ngit remote -v # show origin \n```\n\n# Token\n\n* Settings **\u003e** Developer settings **\u003e New personal access token**\n* Save your **private token***\n```\nghp_1BX2Kw9snvtQq6ttc9vX...uh\n```\n\n# Global Config\n\n**Configure Global UserName**\n\n```bash\ngit config --global user.email “youremail@domain.com”\ngit config --global user.name “gitusername“\ngit config --list # list data\n```\n* en: To edit file\n```bash\nnano ~/.gitconfig # edit file\n```\n\n* en: Save username for 8h.\n```bash\ngit config --global credential.helper ‘cache –timeout=28800’\n```\n\n* en: Save username permanently.\n```bash\ngit config --global credential.helper cache\n```\n \n## Basic Functions\n\n[Basic Functions](https://www.gnial.com.br/gnialhelp/git-and-github-basic-functions/)\n\n## Push Origin Master\n\n* en: Change file or create a new file and send to repositoty:\n\n```bash\ngit add .\ngit commit -m \"words\"\ngit push origin master # or git push\n```\n\n### Change Branch Name\n```bash\n# go to branch\ngit checkout branch-name\n# a new\ngit checkout -m new-branch\n# rename your current branch\n# -m --force\ngit branch -m new-branch-name\n# list all branchs\ngit status -a\n# change remote branch too\ngit branch -m :old-branch-name new-branch-name\n# finaly remote upstream (-set-upstream-to define future push and sync branchs)\n# pt-BR: finalmente define upstream remoto (-set-upstream-to define onde os próximos push \n# devem ser enviados, mantendo a branch local e remota em sincronia)\ngit push origin -u new-branch-name\n```\n\n```bash\ngit remote -v\n```\n[Ref](https://devconnected.com/how-to-change-branch-name-on-git/#:~:text=Change%20Branch%20Name.%20In%20order%20to%20change%20a,to%20the%20branch%20that%20you%20want%20to%20rename.)\n\n\n# Branch\n\n## Create Branch\n\n```bash\n# option 1\ngit branch new-branch-name\ngit checkout new-branch-name\n# option 2\ngit checkout -b new-branch-name \n# no necessary -b if branch exists\n```\n[Ref](https://www.freecodecamp.org/portuguese/news/tutorial-de-git-checkout-remote-branch/)\n\n## Staus / Push\n\n```bash\n# status\ngit status\n# ... add and commit\ngit push origin new-branch-name\n```\n\n## Merge Branches\n\n```bash\n# change to master or master branch\ngit checkout master\n# merge master \u003c- new-branch-name\ngit merge new-branch-name\n```\n\n* en: Now send changed files to repository master\n```bash\ngit add .\ngit commit -m \"merge commit\"\ngit push origin master\n# or\ngit push\n```\n\n## Find Branches\n\n* en: On GitHub open repository and find above files a link named BRANCHES. All branches storages on this page\n```bash\n# to list brachs localy\ngit branch\n# list too remote branchs\ngit branch -a\n```\n\n## Log\n\n* en: Show pushes\n```bash\ngit log\ngit log --oneline # short\ngit log --all --decorate --oneline --graph # nice | highlight\n# to remember flags: \"A DOG\"\n# A --all\n# D --decorate\n# O --oneline\n# G --graph\n```\n\n## Delete Branch\n\n* en: After merge with master\n```bash\ngit brash -d new_branch_name\n```\n## Alias | Shotcuts Commands\n\n* en: Create alias\n```bash\n# to create shotcut \"dog\"\n# command \"log --all --decorate --oneline --graph\"\ngit config --global alias.dog \"log --all --decorate --oneline --graph\"\n```\n* en: Remove alias\n```bash\ngit config --global --unset alias.dog\n```\n\n## Fork Original\n\n* en: Send your files to origin fork repository\n```bash\ngit push --set-upstream origin master\n```\n\n## Previous Commits and Branchs\n\n\u003e pt: Qual a diferença entre RESET e REVERT?\n\u003e * **RESET** - Aponta para uma COMMIT e apaga tudo que foi criado ou alterado após essa commit específica. Perdendo todo seu histórico. \n\u003e * 1,2,[3],4,5 -\u003e 1,2,3\n\u003e * **REVERT** - Reverte uma COMMIT específica, as alterações dessa commit escolhida será revertida mas o histórico posterior mantido. \n\u003e * 1,2,[3],4,5 -\u003e 1,2,4,5\n\n#### 1 of 4 ) Previous Branch @{-1}\n\n[Link](https://marcgg.com/blog/2015/10/18/git-checkout-minus/)\n[Link](https://stackoverflow.com/questions/7206801/is-there-any-way-to-git-checkout-previous-branch)\n\n```bash\ngit checkout @{-1} # back -1 branch history\ngit checkout -\n```\n#### 2 of 4 ) Previous Commit RESET | REVERT\n\n[Link](https://stackoverflow.com/questions/3639115/reverting-to-a-specific-commit-based-on-commit-id-with-git)\n\n**RESET**\n\n```bash\ngit log --oneline # show commits\n# copy head commit, example: c14809fa or c14809fafb08b9e96ff2879999ba8c807d10fb07\n# Won't have to type the entire sha, just a little bit will work\ngit reset --sorf c14809fa \ngit reset --mixed c14809fa \ngit reset --hard c14809fa\ngit reset --hard HEAD~1 # previous 1 back\ngit reset --hard HEAD~2 # previous 2 back\ngit commit\n```\n\n**REVERT**\n\n# This will revert the last commit:\n```bash\ngit revert HEAD\n```\nOr\n```bash\ngit log --oneline # show commits\ngit revert c14809fa\ngit revert c14809fa 0d1d7fc32  # 2 commits\ngit revert c14809fa..0d1d7fc32 # range commits\n# flags\ngit revert c14809fa --no-edit # no open file revert\ngit revert c14809fa --no-commit # no commit this revert\n# final\ngit commit\n```\nRevert error: go back\n```bash\ngit revert --abort\n```\n\n#### 3 of 4 ) Hard delete unpublished commits\n\nIf, on the other hand, you want to really get rid of everything you've done since then, there are two possibilities. One, if you haven't published any of these commits, simply reset:\n\n**Bad idea**\n\n```bash\n# This will destroy any local modifications.\n# Don't do it if you have uncommitted work you want to keep.\ngit reset --hard 0d1d7fc32\ngit commit\n\n**Better idea**\n\n# Alternatively, if there's work to keep:\ngit stash\ngit reset --hard 0d1d7fc32\ngit stash pop\n# This saves the modifications, then reapplies that patch after resetting.\n# You could get merge conflicts, if you've modified things which were\n# changed since the commit you reset to.\n```\n\n#### 4 of 4 ) Undo published commits with new commits\n\nOn the other hand, if you've published the work, you probably don't want to reset the branch, since that's effectively rewriting history. In that case, you could indeed revert the commits. With Git, revert has a very specific meaning: create a commit with the reverse patch to cancel it out. This way you don't rewrite any history.\n\n```bash\n# This will create three separate revert commits:\ngit revert a867b4af 25eee4ca 0766c053\n\n# It also takes ranges. This will revert the last two commits:\ngit revert HEAD~2..HEAD\n\n#Similarly, you can revert a range of commits using commit hashes (non inclusive of first hash):\ngit revert 0d1d7fc..a867b4a\n\n# Reverting a merge commit\ngit revert -m 1 \u003cmerge_commit_sha\u003e\n\n# To get just one, you could use `rebase -i` to squash them afterwards\n# Or, you could do it manually (be sure to do this at top level of the repo)\n# get your index and work tree into the desired state, without changing HEAD:\ngit checkout 0d1d7fc32 .\n\n# Then commit. Be sure and write a good message describing what you just did\ngit commit\n```\n\n## Error\n#### Error/Problem\nfatal: The current branch master has no upstream branch.\nTo push the current branch and set the remote as upstream, use\n```git\ngit push --set-upstream origin master\n```\n#### Soluction \n[stackoverflow](https://stackoverflow.com/questions/23401652/fatal-the-current-branch-master-has-no-upstream-branch)\n[stackoverflow](https://stackoverflow.com/a/17096880/6309)\n```bash\n$ git push -u origin main\n# or \n$ git push -u origin --all\n# or \n$ git config --global push.default current\n```\n\n#### Error/Problem\n``` \ngit error fatal: Invalid branch name: 'HEAD'\n```\n#### Solution \n```\n$ git config --global init.defaultBranch main\n$ cat ./.git/HEAD\n$ rm -rf ./.git/HEAD # if necessary\n$ git init\n$ git checkout main --force\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnatancabral%2Fgit-start","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnatancabral%2Fgit-start","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnatancabral%2Fgit-start/lists"}