While Git is a local version control system, GitHub is a cloud-based platform for hosting Git repositories.
Files & Folders #
- Git
- README.md
- .gitignore
- .gitattributes
- GitHub Actions
- .github/workflows
- *.yml
Git Command Lines #
git versiongit config list --show-originLists system, global, and local configurations and their origin.
git config --global user.name <name>git config --global user.email <email>git clone <url>git initgit statusgit stashCuts the changes in the current project and pastes them into the stash archive.
git stash push <file-name>Cuts the changes in the specified file and pastes them into the stash archive.
git stash listLists all stashes.
git stash showShows the changes in the latest stash.
git stash popCuts the latest stash in the stash archive and pastes it into the current project.
git stash applyCopies the latest stash in the stash archive into the current project.
git stash dropDeletes the latest stash in the stash archive.
git add .Stages all changes.
git commitCreates a commit with all staged changes.
One task per commit. Avoid combining multiple tasks into a single commit.
git revert <commit-id>Creates a commit that undoes the changes of the specified commit.
git reset <commit-id>Deletes all commits after the specified commit, keeps the changes unstaged, and preserves the specified commit. This has the implicit
--mixedflag, which is the default.git reset --soft <commit-id>Deletes all commits after the specified commit, keeps the changes staged, and preserves the specified commit.
git reset --hard <commit-id>Deletes all commits after the specified commit, also deletes the changes, and preserves the specified commit.
git logLists the commit history.
git log -S <string>Finds commits where the specified string was added or removed.
git showShows the latest commit with its diff.
git branchLists all local branches.
git branch --verbose (-v)Lists all local branches verbosely.
git branch --verbose --verbose (-vv)Lists all local branches more verbosely.
git branch --all (-a)Lists all local branches and remote repository branches.
git branch <branch-name>Creates the specified branch.
git branch --delete (-d) <branch-name>Deletes the specified branch.
git branch --move (-m) <specified-branch-name> <new-branch-name>Renames the specified branch.
git checkoutShows a brief status of the current branch.
git checkout <branch-name>,git switch <branch-name>Moves from the current branch to the specified branch.
Uncommited changes are carried over to the specified branch if there is no conflict.
git checkout -,git switch -Moves to the previous branch or commit.
git checkout -b <branch-name>,git switch --create (-c) <branch-name>Creates the specified branch and moves to it.
git checkout <commit-id>,git switch --detach <commit-id>Moves the HEAD directly to the specified commit without being attached to any branch.
git checkout -- <file-name>,git restore <file-name>Restores the specified file to the last commit state.
git merge <branch-name>Merges the specified branch into the current branch.
git merge --abortAborts the paused merge process due to conflicts and restores the current branch to its pre-merge state.
git merge --continueResumes the paused merge process after resolving conflicts and staging the resolved changes.
git rebase <branch-name>Cuts the commits of the current branch that diverge from the specified branch and pastes them onto the specified branch to create a linear history. After rebasing, the specified branch should be fast-forward merged.
git rebase --abortAborts the paused rebase process due to conflicts and restores the current branch to its pre-rebase state.
git rebase --continueResumes the paused rebase process after resolving conflicts and staging the resolved changes.
git remoteLists all remote repository aliases.
git remote --verbose (-v)Lists all remote repository aliases and their URLs.
git remote add <remote-repository-alias> <remote-repository-url>Creates the alias for the remote repository and connects the current project to it.
git remote remove (rm) <remote-repository-alias>Disconnects the current project from the specified remote repository.
git remote set-url <remote-repository-alias> <remote-repository-url>Updates the URL of the specified remote repository.
git push <remote-repository-alias> <branch-name>Uploads the local branch to the remote repository branch that has the same name as the local branch. If the local and remote names are different,
<branch-name>will be<local-branch-name>:<remote-repository-branch-name>git push --set-upstream (-u) <remote-repository-alias> <branch-name>Uploads and remembers this connection. Thereafter, you can simply run
git push,git fetch, orgit pullwithout arguments.
git fetch <remote-repository-alias> <remote-branch-name>Downloads the changes from the specified remote repository branch without merging them.
git pull <remote-repository-alias> <remote-branch-name>Downloads the changes from the specified remote repository branch and merges them into the current branch.
GitHub Actions is a continuous integration and continuous deployment (CI/CD) service.
GitHub Actions provides secrets, variables, artifacts, and outputs.
GitHub Actions consists of workflows. Workflows are triggered by events and have one or more jobs.
Jobs run on a runner and have one or more steps. Jobs run in parallel by default but can run sequentially by specifying needs.
Steps execute a shell command, a custom action, or a third-party action. Steps run in order.