Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
69 views

Local & Remote Repos: View Existing Remote Repositories

This document summarizes common Git commands for working with local and remote repositories, including cloning repositories, viewing status and commits, staging and committing files, adding remote repositories, pushing and pulling changes, branching, stashing, and resolving conflicts. Key commands include git clone to download a remote repository locally, git status to check the status of files, git add and git commit to stage and commit changes, and git push and git pull to sync changes with remote repositories.

Uploaded by

Mahesh Abnave
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views

Local & Remote Repos: View Existing Remote Repositories

This document summarizes common Git commands for working with local and remote repositories, including cloning repositories, viewing status and commits, staging and committing files, adding remote repositories, pushing and pulling changes, branching, stashing, and resolving conflicts. Key commands include git clone to download a remote repository locally, git status to check the status of files, git add and git commit to stage and commit changes, and git push and git pull to sync changes with remote repositories.

Uploaded by

Mahesh Abnave
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Local & Remote repos

View existing remote repositories


$ git remote

Clone Repository Locally


$ git clone github-repo-url

Git Status
$ git status

Staging
 Add a specific file to commit
$ git add filename

 Add untracked file to commit


$ git add .

 Add files of certain extension


$ git add *.html

 Excluding file from staging


Create .gitignore file in git repo home (in the same folder in which .git folder exists) and specify
names or patterns of the files that we don’t want to track on git.
$ touch .gitignore
Add the patterns/file names to exclude to this file.
You may add .gitignore to git.

 Automatically stage and commit tracked files


Untracked files are not committed
$ git commit –a –m ‘xyz’

Commit the files ?in staging?


 Specify the commit message
$ git commit –m message

 S

Commit Logs
$git log

Add Origin
$ git remote add origin repo-url

To add additional repositories


$ git remote add repo-name repo-url

Push the commits ?in staging? to repo


$ git push –u origin master

-u origin master is required only while pushing first time. Next time onwards `$ git push` is sufficient.

Create file in local


$ touch filename.extension
Pull the latest repo to local
$ git pull origin master

Fetch the latest branch


$git fetch origin
Pulls the latest data of the remote branch to the local disk. Does not perform merging.

Branching
Create a branch
$ git branch MyBranch

Switch to branch
$ git checkout MyBranch

When you switch to the particular branch the local folder contents change to resemble to the contents
of the switched branch.

To Merge branch

1. Checkout/switch to destination branch say master branch


$ git checkout master
2. Merge the source brance
$ git merge MyBranch

Stashing
http://git-scm.com/book/en/v1/Git-Tools-Stashing

$ git stash
$ git stash list
$ git stash apply
$ git stash apply --index
$ git stash drop --index
$ git stash pop

Dealing with conflicts

Mergetool
$ git merge tool

You might also like