Day12 #90DaysOfDevOps Challenge

Git Cheat-Sheet

Day12 #90DaysOfDevOps Challenge

⭐Git configuration

Git config

--local = For that specific repo.

.git directory: .git/config

--global = For the specific user in an OS and will be applied to all the repos.

Directory: C:\Users\.gitconfig

--system = For all the users in that machine.

git config --global user.name “Your Name”

Set the name that will be attached to your commits and tags.

git config --global user.email

Set the e-mail address that will be attached to your commits and tags.

⭐Set Remote repository

git add remote repo_here

This command adds a remote repository to your local repository.

git remote -v

Shows all remote repositories for your local repository,

⭐Basic Commands

git init [Repo name]

Initialize a new local repository.

If [Repo name] is provided, Git will create a new directory name [Repo name] and will initialize a repository inside it.

If [Repo name] is not provided, then a new repository is initialized in the current directory.

git clone [Repo url]

Downloads a repo with the entire history from the remote repository.

git status

Displays the status of your working directory. Options include - new, staged, and modified files.

git add filename or .

Add one or all files to the staging area.

git commit -m "message"

Create a new commit from changes added to the staging area. The commit must have a message!

git diff [file]

Show changes between the working directory and the staging area.

git diff --staged [file]

Shows any changes between the staging area and the repository.

git stash

Put current changes in your working directory into the stash for later use.

git stash pop

Apply stored stash content into the working directory, and clear stash.

git stash drop

Delete a specific stash from all your previous stashes.

git branch

List all the branches.

git branch [branch name]

Create a new branch.

git checkout [branch name]

Switch to a particular branch.

git checkout -b [branch name]

Create a new branch and switch to it.

git branch -d [name]

Remove the selected branch, if it is already merged into any other. -D instead of -d forces deletion.

git log --oneline --graph --decorate

An overview with reference labels and a history graph. One commit per line.

git fetch [remote]

Fetch changes from the remote, but do not update tracking branches.

git pull [remote]

Fetch changes from the remote and merges the current branch with its upstream.

git push [remote]

Push changes from the local repo to the remote repo.

⭐Advance Commands

git merge [branch name]

Merge changes from the target branch to the current branch. Creates a merge commit that shows the history of changes coming from the target branch.

git rebase [branch name]

Merge changes from the target branch to the current branch through rebase which creates linear history.

git reset [commit ID]

Reset the head of the branch to a specified commit. options available are soft, mixed, and hard.

git revert [commit ID]

Create a new commit, reverting changes from the specified commit.

git cherry-pick [commit ID]

Merge only specified commits from the target branch to the current branch.


Thank you for Reading! 📘