0% found this document useful (0 votes)
18 views3 pages

GIT Commands

This document provides instructions for setting up Git on an Ubuntu machine and connecting a local Git repository to a remote GitHub repository. It includes steps for configuring user information, initializing and committing to a local repo, generating a personal access token, creating a remote repo on GitHub, pushing the local repo to the remote, cloning an existing remote repo locally, and pulling changes from the remote. It also provides commands for viewing commit logs, diffs, staging/unstaging files, deleting files and branches, ignoring files, and merging branches.

Uploaded by

jkjlab01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views3 pages

GIT Commands

This document provides instructions for setting up Git on an Ubuntu machine and connecting a local Git repository to a remote GitHub repository. It includes steps for configuring user information, initializing and committing to a local repo, generating a personal access token, creating a remote repo on GitHub, pushing the local repo to the remote, cloning an existing remote repo locally, and pulling changes from the remote. It also provides commands for viewing commit logs, diffs, staging/unstaging files, deleting files and branches, ignoring files, and merging branches.

Uploaded by

jkjlab01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy