Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Git/Github Quick Start Reference Document
Caio Cesar
Caio Cesar

Posted on • Edited on

Git/Github Quick Start Reference Document

Git and GitHub

GitHub- A cloud platform used for collaborating that makes use ofgit.

Features of GitHub:Issues,Discussions,Pull requests,Notifications,Labels,Actions,Forks,Projects.

Git- Allows people to contribute to projects with the use of a distributed version control system (DVCS).

In its most basic form git is a content tracker

Basic Git Commands

  • git init - Initialized an existing git repository or creates an empty git repository.

Git Init Screenshot

  • git Status - Displays the status of the working tree. It could inform changes to be committed, changes not staged for commit, untracked files or if the tree is clean.

Git Status Screenshot

  • git add - Add file contents to the index/working tree.

Git Add

Git Status Screenshot

  • git commit - Record changes to the repository

Git Commit

  • git log - Displays commit logs history for the current repository.

Git log Screenshot

Branches

Branch- Git branches are a reference to a snapshot of your changes. By default git initializes with the branch name ofmain ormaster.

  • git branch command can also show the list of existing branches for a repository, create new branches or delete existing ones.

List

  • The current selected branch in the screenshot bellow ismaster that's why it has an asterisk by its name and its color is green.Git Branch List

Create

  • Creates a new branch based of the selected branch namedb1.Git Branch Create

List

  • Lists two branches from the repo.Git Branch List

HEAD

  • The HEAD of the current project is a reference to the selected branch that isrefs/heads/master.

  • git switch - Allows one to switch the selected branch to an existing branch.

Git Swtich

  • Now the HEAD of the branch isrefs/heads/b1.

  • git checkout - Also allows one to switch the selected branch to an existing branch o create new branches.

Git Checkout

  • Now the HEAD of the branch is back torefs/heads/master.

Basic Git Knowledge

Repository- A project that may contain files and folders with versioning.

Commit- represents a change with an assigned a unique ID to 1 or many files.

Pull Request- Responsible for alerting that a commit is ready for merging between branches.

Pull- Thegit pull command retrieves all base branch commits that hasn't been applied to the current branch.

Cloning and forking

Cloning a Repository- Represents a copy of the repository and its history to a machine.

Forking a Repository- Represents a copy of a repository in a GitHub account.

Merging

Merge- Allows one to adds the changes in the pull request and branch into thetarget branch.

  • Lets say you have two branches master and b1 with the same ReadMe.txt file and different content on them. Lets assume you want the content in theb1 branch to merge into themaster branch. To start the merge you can switch to the master then run the following command.

  • git merge b1

git Merge

  • As you can see from the screenshot above since the content differs there is a merge conflict that needs to be resolved.

  • Now you can resolve the merge conflict in the ReadMe.txt file then add and commit the merged file into themaster branch.

Git Merge

Merge Conflict- Occurs when a merge is attempted and changes to the same line of code from parallels changes.

Resolving Merge Conflicts- Git can generate a temporary file that contains differences from each branch. One can manually select what should or shouldn't be merged.

Preventing Merge Conflicts- pull updates frequently and keep branches close to base.

Rebasing

  • Lets say you have two branches master and b1 with the same ReadMe.txt file and different content on them as seen in the figure bellow.

2 branches

  • The rebase command such asrebase master changes the base of the command to move b1 to the end of master as displayed in the image bellow:

Rebase

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Software Architect | Researcher
  • Education
    Computer Science
  • Work
    Software Architect
  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp