Git Useful Commands

Installing Git:

$ sudo yum -y install git

Configure name and email:

$ git config --global "firstname lastname"
$ git config --global

Authenticate with private SSH key:

$ ssh-keygen

Clone a repository (git clone):

$ git clone <remote repository url>

Create a local repository (git init):

$ git init

Get the status of a repository (git status):

$ git status

Stage files for the next commit (git add):

$ git add <file>
$ git add .

Commit files (git commit):

$ git commit -m "commit message"

Push changes to remote repository (git push):

$ git push

Checkout to another branch (git checkout):

$ git checkout <branch name>

Tags (git tag):

$ git tag sometext HEAD
$ git tag
$ git push --tags

Merge (git merge):

# Be sure that we work on the master branch
$ git checkout master
# Create a new branch and checkout into
$ git branch new-branch
$ git checkout new-branch
# Create some new files
# vi file.txt etc...
# Stage files and commit to new-branch
$ git add .
$ git commit –m ”a commit message"
# Checkout to master branch
$ git checkout master
# Merge new-branch with master branch
$ git merge new-branch

Written by

DevOps engineer, loves Linux, Python, cats and Amiga computers

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store