You are on page 1of 3

➔ Open a terminal on Ubuntu machine.

Install Git if not already installed:

sudo apt install git

➔ Configuring global user and email

git config --global user.email <you@example.com>

git config --global user.name <Your Name>

➔ Git initialization

git init <repo_name>

cd <repo_name>

➔ To check git status

git status

➔ Create and edit one or more file which you want git to track:

nano <file_name>

➔ Add file to git staging area:

git add <file_name>

➔ Commit to local repo:

git commit -m "<message of your choice>"

➔ Create a new personal account in github at www.github.com if you do not have one using a
personal email id

➔ Create a personal access token by following steps mentioned in below article and save personal
access token generated at the last step as it is visible only once:

https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-
secure/creating-a-personal-access-token

➔ Create a new remote repository in github under your user


and copy the https link of the repository created and save it as required for next step

➔ Create the connection with remote repo

git remote add origin <https_link_of_repo_copied_in_previous_step>

➔ Push the local repository to remote repo using user id and Personal Access Token generated and
saved earlier

git push origin master

➔ If you do not want to specify Personal Access Token every time a push happens, you can set
below variable and after this you will need to specify user id and token only once and it will be
stored for ever.

git config --global credential.helper cache

➔ Creating a copy of remote repo in your local

git clone <https link>

➔ If the local repo already exists and you need to only get the remote repo changes in your local

git pull origin master

➔ Check the logs

git log --oneliner


➔ Check diff between working area and staging

git diff <file_name>

➔ Check diff between staging and local repo

git diff --staged <file_name>

➔ Un stage a staged file

git reset HEAD <file_name>

➔ Remove a file from repo/staged and working directory

git rm -f <file_name>

git commit -m "<deleted file>"

➔ Remove a file from repo/staged but not from working directory

git rm --cached <file_name>

git commit -m "<deleted file>"

➔ Provide details of file and folders in .gitignore which needs to be ignored by git

.gitignore

➔ Command to create a new branch and check it out

git checkout -b <branch_name>

➔ Command to connect to existing branch

git checkout <branch_name>

➔ Command to merge branch (Before running this connect to the branch you want to merge)

git merge <branch_name>

➔ Command to delete branch

git branch -d <branch_name>

You might also like