0% found this document useful (0 votes)
32 views

Git Commands

The document outlines 24 common Git commands and concepts. It begins with commands for configuring user information, navigating directories, cloning repositories, checking status, staging and committing changes, pushing to remote repositories, branching, merging, resolving conflicts, undoing changes, and viewing history. It also summarizes the typical workflow of making changes locally, committing, and pushing to a remote, as well as forking repositories on GitHub to contribute changes without affecting the original.

Uploaded by

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

Git Commands

The document outlines 24 common Git commands and concepts. It begins with commands for configuring user information, navigating directories, cloning repositories, checking status, staging and committing changes, pushing to remote repositories, branching, merging, resolving conflicts, undoing changes, and viewing history. It also summarizes the typical workflow of making changes locally, committing, and pushing to a remote, as well as forking repositories on GitHub to contribute changes without affecting the original.

Uploaded by

hammad sajid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

GIT COMMANDS

1. git config --global user.name


To set user name
2. git config --global user. email
To set the email
3. cd directory name
To move to specific directory
4. cd ..
To move one step back from current directory
5. git clone <link of repository>
To clone a repo to local machine
6. ls
Show all the files of current folder/ repository
7. ls -a
Show hidden files of repository/folder
8. git status
display the status of code

Four stages of git code / files


1. untracked (file which git didn't track)
2. modified (changed)
3. unmodified(unchanged)
4. staged (ready to committed)

9. git add <filename>


To add new or changed file of your working directory to git staged area
10.git commit -m <message>
It is record of changes
11.git push origin main
use to push local repo to remote repo
12.mk dir <folder name>
use to make folder/directory
13.git init
use to make local directory a git repository
14.git remote add origin <link of remote repo>

15.git remote -v
to check remote repo
16.git branch
to check branch
17.git branch -M "new name of branch"
use to rename git branch

WORKFLOW OF GIT
GitHub repo  Clone to local machine  Make changes in repo  Then use git add
Then use git commit  push the code to remote repo.
18.git checkout <branch name>
To navigate to another branch
19.git checkout –b <new branch name>
To create a new branch
20.git branch –d <branch name >
To delete a branch
21.git diff<branch name>
To compare two branches
22.git merge<branch name>
To merge two branches

PULL REQUEST THROUGH GITHUB

It let you to tell others about the changes you have pushed to branch in a repository of
GitHub.

23.git pull origin main


Used to fetch and download the content of remote repo to local repo

RESOLVING MERGE COFLICT

An event that take place when git is unable to automatically resolve diffrences in code
between two commits (changes)

UNDOING CHANGES

Case1: Staged changes


git reset <filename> (changes in one or two files)
git reset (changes done in multiple files)

Case2: Commited changes (for one commit)


git reset HEAD~1
Case3: Commited changes (for many commits)
git reset <commit hash >
git reset -- hard <commit hash>

24.git log
Used to see the history of commits

FORKING IN GITHUB

Forking creates your own copy of a repository in a remote location (for example,
GitHub). Your own copy means that you will be able to contribute changes to your
copy of the repository without affecting the original repository.

You might also like