Is A Powerful Version Control System That Allows You To Track Changes in Your Project's Codebase
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
$ 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)
To untrack a file
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:
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
Branching
Switched to branch
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