{"id":20493631,"url":"https://github.com/code-lucidal58/git_inception","last_synced_at":"2025-10-03T18:05:51.119Z","repository":{"id":88633381,"uuid":"110645194","full_name":"code-lucidal58/git_inception","owner":"code-lucidal58","description":"All you need to know to start with git! Keeping commiting ;) #iykwim","archived":false,"fork":false,"pushed_at":"2019-05-25T07:42:11.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-16T05:55:44.108Z","etag":null,"topics":["git","git-workflow","gitbash","github"],"latest_commit_sha":null,"homepage":null,"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/code-lucidal58.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-14T05:33:44.000Z","updated_at":"2019-04-03T05:35:14.000Z","dependencies_parsed_at":"2024-03-25T14:01:10.642Z","dependency_job_id":null,"html_url":"https://github.com/code-lucidal58/git_inception","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/code-lucidal58%2Fgit_inception","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-lucidal58%2Fgit_inception/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-lucidal58%2Fgit_inception/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-lucidal58%2Fgit_inception/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/code-lucidal58","download_url":"https://codeload.github.com/code-lucidal58/git_inception/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242075255,"owners_count":20068224,"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":["git","git-workflow","gitbash","github"],"created_at":"2024-11-15T17:36:02.555Z","updated_at":"2025-10-03T18:05:51.037Z","avatar_url":"https://github.com/code-lucidal58.png","language":null,"readme":"# GIT BASICS\nIt is tough to work without Git in this world of uncertainties. You never know when you\ndesktop goes down and BOOM you lost all your projects. It is recommended for every\ndeveloper to be committed to git ;)\n\u003eGit is a software that allows you to keep track of changes made to a project over time.\nGit works by recording the changes you make to a project, storing those changes, then\nallowing you to reference them as needed.\n\n## Few key concepts\nGit is a distributed and decentralised source control system. Most operations\nare local. Internet is required when changes are to be pushed to a remote repository.\nEach **commit** is identified with SHA1 hash. **HEAD** is pointer to last commit\nin current branch. **Remote** is a related repository that is not local.\n\n## Going to some depth\nA git project has three main parts:\n1. **Working directory**: This is the place where the user make changes to the\nfile in the project. A folder is converted to a git repository using ```git init```.\nTo clone(bring to local system) a git repository ```git clone \u003crepo_url\u003e``` is executed.\n2. **Staging area**: This is the place where all the changes the project are\nlisted. Local changes are moved to staging area using ```git add \u003cfile/folder names\u003e```.\n3. **Git Repository**: all latest files/folders are saved as a different version in the\nproject.This is done using ```git commit -m\u003cmessage for the commit\u003e```. Adding message\nto the commit is mandatory.\n\n***NOTE***: As shortcut to add and commit all changes in tracked files in working\ndirectory is\n```shell\ngit commit -am \\\"\u003cmessage\u003e\\\"\n```\nLocal changes to Remote repository: ```git push```  \nRemote repository changes to Local: ```git pull```\n\n\u003eIn git workflow, changes are made in the working directory, files are added to\nthe staging area and saved in the repository.\n\n## Important git commands\n**Get Help**  \n```shell\ngit help\n```\nThis shows the different options available in git. ```git help \u003ccommand\u003e``` will show the\ndocumentation of the specified command only.  \n\n**Configuring Git**  \nGit must have the owner's name and email ID. This is preferably the user name and\nemail ID that is linked to online VCS like Github or BitBucket.\n```shell\ngit config --global user.name \"\u003cusername\u003e\"\ngit config --global user.email \"\u003cemail address\u003e\"\n```\nThese details can be viewed using ```git config --global --list```. The configuration\nsettings are saved in the working directory in a file name **.gitconfig**.\n\n**Creating a folder along with git initialisation**  \n```shell\ngit init \u003cproject-folder-name\u003e\n```\nA **.git** folder is created whenever git is initialised.\n\n**Status of changed files**  \n```shell\ngit status\n```\nUntracked files mean the files has some changes but git has not started tracking them.\n\n**Add a file to staging area**  \n```shell\ngit add filename #OR\ngit add * #OR\ngit add . #OR\ngit add filename_1 filename_2 #OR\ngit add -A\n```\nHere, each command has their own importance and may behave different in\ndifferent situations.\n\n**See the changes made to a staged file**  \n```shell\ngit diff filename\n```\n\n**View all commits**  \nGit stores history of commits of a branch in chronologically order in repository.\nThis is helpful when a reference to previous versions of project is required.\n```shell\ngit log\n```\nThis has SHA1 key, author, date and message for each commit. Flags can be added\nto have a more concise view of the commits. Try this:\n```shell\ngit log --oneline --graph --decorate --color\n```\n\n**Move files to different directory inside repository**  \nHere *index.html* is moved from the root directory to a directory named *web* inside root.\n```shell\ngit mv index.html web\n```\n\n## Gitignore\nGit provides user an option to exclude files or filename following a pattern from\nbeing added to staging area. This is done by creating a file named **.gitignore**.\nOne pattern per line. Here is a sample *.gitignore* file.\n```text\n__pycache__/*\n.idea/*\n*/__pycache__/*\n```\n\n## Backtracking\nAs mentioned earlier, **HEAD** is the current commit. To look for changes in it:\n```shell\ngit show HEAD\n```\nThe output is same as _git log_ plus changes made to file.\n\n**Removing file from staging area**\n```shell\ngit rm --cached filename\n```\nGit will stop tracking this file, as well.\n\n**Removing file from current commit**  \n```shell\ngit reset HEAD filename\n```\nGit will keep tracking this file but removes it from latest commit.\n\n**Revert back to the content before the latest commit**  \n```shell\ngit checkout HEAD filename\n```\nThere is a shortcut to this command:\n```shell\ngit checkout -- filename\n```\nThe first 7 characters of the sha of last commit can also be used to unstag changes.\n```shell\ngit reset 96g12673\n```\n\n### Git Branching\nThe default branch that we work is _master_. Git provides option to create branches to experiment with versions of the project. The main project will be _MASTER_ branch. The other branches need to merged to MASTER to update the main repository. New branch is a different version of the Git project. It will have all commits from MASTER. To check the current branch:\n```shell\ngit branch\n```\nThe output will be the list of all branches with asterisk(\\*) mark on the current branch. To create a new branch:\n```shell\ngit branch new_branch\n```\nTo switch to another branch:\n```shell\ngit checkout branch_name\n```\nAfter switching, staging and commiting is done in the same way as before. To merge the changes with MASTER branch, first switch to master branch using _git checkout master_, then:\n```shell\ngit merge branch_name\n```\nThere will be merge conflicts if the same file is edited in master as well as any other.\nMany branches can be created in a Git project. But, the end requirements reflecting all changes into the _master_ branch. After merging the branches can be deleted:\n```shell\ngit branch -d branch_name\n```\nIf a branch is not merged to _master_, then to delete that branch, run:\n```shell\ngit branch -D branch_name\n```\n\n## Generating SSH keys\n* Open command prompt and navigate to root user directory. E.g. /User/aanisha/\n* Move into *.ssh* folder. If it does not exist, create one : ```mkdir .ssh```.\n* ```ssh-keygen -t rsa -C \"aanisha.mishra05@gmail.com\"``` to create a new SSH key.\n* It will ask for a file name to save the details and a password to protect. Give the details as per requirement.\nNow, two file are created based on the name given by user. One of them has *.pub* extension.\nThis file has the content that can be copied into on of the VCS cloud clients like Github.\nThe key generated will be unique to your laptop.\n\nNow, come back to the same cmd session, and run ```ssh -T git@github.com```(provided you\nhave added the key to your GitHub profile). Your  laptop and GitHub and now in mutual connection.\nThis process is recommended for remote works.\n\n## Working with collaborates\n\u003eA __remote__ is a shared Git repository that allows multiple collaborators to work on the same Git project from different locations. Collaborators work on the project independently, and merge changes together when they are ready to do so.\n\nTo contribute to a remote project, the project first needs to be cloned to local. This is done as:\n```shell\ngit clone remote_location clone_name\n```\n_repo_location_ is address of the place where the repository is. It can be a file path or URL. _clone_name_ is the name of the directory where Git project is cloned. By default, git names the remote connection as __origin__. All remotes can be views using:\n```shell\ngit remote -v\n```\n\n#### Push an existing directory to remote\n* Create a repository in remote.\n* Copy the SSH link of the repository\n* Open command prompt inside the local directory and run ```git remote add origin \u003cthe link copied\u003e```.\n* Git pull to bring all remote changes to local.\n\n## Git Remote  Command while collaborating\nTo reflect changes in git to you system:\n```shell\ngit fetch\n```\nThis will not update the local repository but will bring the changes to remote branch.\nTo integrate origin (master) into local repository, __git mergin origin/master__ is used.\n\nTo push changes to the origin:\n```shell\ngit push origin branch_name\n```\nAfter pushing the changes to a branch, they can then be merged with master.\n\n***Sources: Udemy, Codecademy***\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode-lucidal58%2Fgit_inception","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcode-lucidal58%2Fgit_inception","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode-lucidal58%2Fgit_inception/lists"}