0% found this document useful (0 votes)
86 views2 pages

Git Commands for Directory Management

To create a new local repository, use 'git init' in an empty directory. To clone an existing remote repository, use 'git clone' followed by the repository URL. The basic Git workflow involves three trees - the working directory containing actual files, the index staging changes, and the local repository storing commits. Files are added to the index with 'git add' and committed locally with 'git commit'. To push local commits to a remote repository, use 'git push origin <branch>' after setting the remote with 'git remote add'. Pull changes from the remote with 'git pull' to merge them locally.

Uploaded by

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

Git Commands for Directory Management

To create a new local repository, use 'git init' in an empty directory. To clone an existing remote repository, use 'git clone' followed by the repository URL. The basic Git workflow involves three trees - the working directory containing actual files, the index staging changes, and the local repository storing commits. Files are added to the index with 'git add' and committed locally with 'git commit'. To push local commits to a remote repository, use 'git push origin <branch>' after setting the remote with 'git remote add'. Pull changes from the remote with 'git pull' to merge them locally.

Uploaded by

Govind Thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd

Git Command Related Document

1. To Create a new repository in your system :


Create directory>goto that directory using terminal or cmd
prompt> type git init
[Link] a repository in local system and create a working
copy of a local repository.
goto that directory where we need to check out codebase>type git
clone along with /path/to/repository.
When we are using remote server then command will be
git clone username@localhost:/path/to/repository
[Link] Flow of Git
your local repository consists of three Trees maintained by [Link] frst
one is
.Working !irectory
which holds the actual fles
The second one is
. n"e#
which acts as a staging area and fnally the third one is
. $%&!
which points to the last commit you have made.
4. To add and Commit
You can propose changes(add it to the index) using
git add !lename which we need to add"
git add #
This is the rst step in the basic git work!ow"To actually commit these
changes use
git commit $m %message for commit&
#ow the le is committed to the $%&' but not in your remote repository
yet"
'.To (ushing changes into remote repository
Your changes are now in the $%&' o( your local working copy"To send
those changes to your remote repository)execute
git push origin master
Changes master to whatever branch you want to connect your repository
to a remote server)you need to add it with
git remote add origin ser)er"
#ow you are able to push your changes to the selected remote server
*. To +pdate and ,erge
to update your local repository to the newest commit) execute
get pull
in your working directory to fetch and merge remote changes"to merge
another branch into your active branch (e"g" master)) use
git merge -ranch"
in both cases git tries to auto*merge changes" +n(ortunately) this is not
always possible and results in conficts" You are responsible to merge
those conficts manually by editing the les shown by git" &(ter changing)
you need to mark them as merged with
git add !lename"
be(ore merging changes) you can also preview them by using
git di. source/-ranch" target/-ranch"
0. To replace local changes
,n case you did something wrong (which (or sure never happens -) you can
replace local changes using the command
git checkout 1 !lename"this replaces the changes in your working
tree with the last content in $%&'" Changes already added to the index)
as well as new les) will be kept",( you instead want to drop all your local
changes and commits) (etch the latest history (rom the server and point
your local master branch at it like this
git fetch origin
git reset 1hard origin2master
3. To see log
in its simplest (orm )you can study repository history using
git log
you can add a lot o( parameters to make the log look like what
you want "To see only the commits o( a certain author use
git log 1author4-o-
To see a very compressed log where each commit is one line
use
git log 1pretty4oneline
.r may be you want to see an &/C,, art tree o( all
branches)decorated with the names o( tags and branches
git log 1graph 1oneline 1decorate 1all
To see only which les have changed
git log 1name$status

You might also like