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

Is A Powerful Version Control System That Allows You To Track Changes in Your Project's Codebase

Uploaded by

Sadatur Rahman
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)
16 views

Is A Powerful Version Control System That Allows You To Track Changes in Your Project's Codebase

Uploaded by

Sadatur Rahman
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/ 9

Git is a powerful version control system that allows you to track

changes in your project's codebase.

Starting a project

o Git init
Create a local repository:
$ git init

Create a new file:

$ touch test.txt

o Git status
Display the state of the working directory and the staging area.
$ git status
Local changes

o Git add
Add a file to staging (Index) area:
$ git add (Filename)

$ git add test.txt

To untrack a file

$ git rm - - cached test.txt

Add all files of a repo to staging (Index) area:


$ git add .
o Git commit
Record or snapshots the file permanently in the version history with a
message.

$ git commit -m " Data is added by Sadat"

Track changes

o Git diff
Track the changes that have not been staged:

$ git diff
Track the changes that have staged but not committed:
$ git diff --staged
Track the changes after committing a file:
$ git diff HEAD
Track the changes between two commits:

$ git diff Git Diff Branches:


$ git diff < branch 2>

o Git show Shows objects:


$ git show

Commit History

o Git log
Display the most recent commits and the status of the head:
$ git log
Display the output as one commit per line:
$ git log --oneline

Displays the files that have been modified:


$ git log --stat

Display the modified files with location:


$ git log --p
o Git blame
Display the modification on each line of a file:
$ git blame <file name>

Branching

o Create a new branch


git branch (branch name)

Switched to branch

git checkout (branch name)


o Create a sub branch into an existing branch:
o git branch (sub branch name) (branch name)
o git branch newly added new

Create a new branch and switch to that branch

o git checkout -b “feature2”

Merging

o Git merge
Merge the branches:
$ git merge
Merge the specified commit to currently active branch:
$ git merge
o Git rebase
Apply a sequence of commits from distinct branches into a final
commit.
$ git rebase
Continue the rebasing process:
$ git rebase -continue Abort the rebasing process:
$ git rebase --skip
o Git interactive rebase
Allow various operations like edit, rewrite, reorder, and more on
existing commits.
$ git rebase -i

Remote

o Git remote
Check the configuration of the remote server:
$ git remote -v
Add a remote for the repository:
$ git remote add Fetch the data from the remote server:
$ git fetch
Remove a remote connection from the repository:
$ git remote rm
Rename remote server:
$ git remote rename
Show additional information about a particular remote:
$ git remote show
Change remote:
$ git remote set-url
o Git origin master
Push data to the remote server:
$ git push origin master Pull data from remote server:
$ git pull origin master

Pushing Updates

o Git push
Transfer the commits from your local repository to a remote server.
Push data to the remote server:
$ git push origin master Force push data:
$ git push -f
Delete a remote branch by push command:
$ git push origin -delete edited

Pulling updates
o Git pull
Pull the data from the server:
$ git pull origin master
Pull a remote branch:
$ git pull
o Git fetch
Download branches and tags from one or more repositories. Fetch the
remote repository:
$ git fetch< repository Url> Fetch a specific branch:
$ git fetch
Fetch all the branches simultaneously:
$ git fetch -all
Synchronize the local repository:
$ git fetch origin

Undo changes

o Git revert
Undo the changes:
$ git revert
Revert a particular commit:
$ git revert
o Git reset
Reset the changes:
$ git reset -hard
$ git reset -soft:
$ git reset --mixed

Removing files

o Git rm
Remove the files from the working tree and from the index:
$ git rm <file Name>
Remove files from the Git But keep the files in your local repository:
$ git rm –cached

You might also like