Skip to content

Latest commit

 

History

History
182 lines (148 loc) · 3.53 KB

git.md

File metadata and controls

182 lines (148 loc) · 3.53 KB

GIT

INSTALLATION

GitHub for Windows Click here

GitHub for Mac Click here

For Linux and Solaris platforms, the latest release is available on the official Git web site. Git for All Platforms http://git-scm.com

SETUP

To configure user information used across all local repositories.

set a name that is identifiable for credit when review version history

git config --global user.name “[firstname lastname]”

set an email address that will be associated with each history marker

git config --global user.email “[valid-email]”

set automatic command line coloring for Git for easy reviewing

git config --global color.ui auto

SETUP AND INIT

Configuring user information, initializing and cloning repositories

initialize an existing directory as a Git repository

git init

retrieve an entire repository from a hosted location via URL

git clone [url]

STAGING

show modified files in working directory, staged for your next commit

git status

add a file as it looks now to your next commit (stage)

git add <filenames>

Tip: git add . adds all files in the current directory.

diff of what is changed but not staged

git diff

diff of what is staged but not yet commited

git diff --staged

Display record of commits made

git log

BRANCHING AND MERGING

List your branches. a * will appear next to the currently active branch

git branch

Create a new branch.

git branch <branch name>

Create branch and changes to it.

git switch -c <branch name>
or
git checkout -b <branch name>

Change to specified branch.

git switch <branch name>
or
git checkout <branch name>

Change to last branch used.

git switch -

REMOTE, PUSH & PULL

Show tracked repos.

git remote -v	

Push changes to the default remote repo.

git push

Tip: you can specify the name of another tracked repo after "push".

Pull changes from default remote repo and merges them into local.

git pull

Pull changes from default remote repo but do not merg into local.

git fetch

Roll back and reset the last staged commit.

git reset HEAD~1

Tip: The number specifies how much commits to reset by, git reset HEAD~2 rolls back 2 commits etc.

Squash multiple commits into one commit.

squash last 4 commits:

git rebase -i HEAD~4

Note: This command will open up default editor then replace "pick" on the second and subsequent commits with "squash".

Squash all commits:

git rebase --root -i

Note: This command will open up default editor then replace "pick" on the second and subsequent commits with "squash".

Stash the current state of the working directory

git stash

Remove the stashed code and apply it in the current working directory

git stash pop

Remove all stashed entries

git stash clear

Remove new/existing files from staged files

git restore --staged <file_name>

Cherry Pick enables arbitrary Git commits to be picked by reference and appended to the current working HEAD.

cherry pick a commit on to main branch:

git cherry-pick commitSHA

Command to merge a specific branch into the current branch

git merge <branch name>

To resolve merge conflict manually open the merge tool

git mergetool

To remove untracked files from the working directory

git clean