Git complete documentation - Help
Git complete documentation
Original post from https://www.atlassian.com/git/tutorials/saving-changes#git
About Remote Repositories
About 90% of version control related work happens in the local repository: staging, committing, viewing the status or the log/history, etc. Moreover, if you're the only person working on your project, chances are you'll never need to set up a remote repository.
Only when it comes to sharing data with your teammates, a remote repo comes into play. Think of it like a "file server" that you use to exchange data with your colleagues.
Let's look at the few things that distinguish local and remote repositories from each other:
Local repositories reside on the computers of team members. In contrast, remote repositories are hosted on a server that is accessible for all team members - most likely on the internet or on a local network.
Technically, a remote repository doesn't differ from a local one: it contains branches, commits, and tags just like a local repository. However, a local repository has a working copy associated with it: a directory where some version of your project's files is checked out for you to work with.
A remote repository doesn't have such a working directory: it only consists of the bare ".git" repository folder.
It's important to stress that the actual work on your project happens only in your local repository: all modifications have to be made & committed locally.
Then, those changes can be uploaded to a remote repository in order to share them with your team. Remote repositories are only thought as a means for sharing and exchanging code between developers - not for actually working on files.
You have two options to get a local repository onto your machine: you can either create a new, empty one or clone it from an existing remote repository.
Creating a remote repository can also be done in two ways: if you already have a local repository that you want to base it on, you can clone this local one with the "--bare" option. In case you want to create a blank remote repository, use "git init", also with the "--bare" option.
Local / Remote Workflow
In Git, there are only a mere handful of commands that interact with a remote repository.
The overwhelming majority of work happens in the local repository. Until this point (except when we called "git clone"), we've worked exclusively with our local Git repository and never left our local computer. We were not dependent on any internet or network connection but instead worked completely offline.
We'll look at each of these commands in the course of the following sections.
Commit changes to head (but not yet to the remote repository):
git commit -m "Commit message"
Commit any files you've added with git add, and also commit any files you've changed since then:
git commit -a
Send changes to the master branch of your remote repository:
git push origin master
List the files you've changed and those you still need to add or commit:
If you haven't connected your local repository to a remote server, add the server to be able to push to it:
git remote add origin <server>
List all currently configured remote repositories:
git remote -v
Create a new branch and switch to it:
git checkout -b <branchname>
Switch from one branch to another:
git checkout <branchname>
List all the branches in your repo, and also tell you what branch you're currently in:
Delete the feature branch:
git branch -d <branchname>
Push the branch to your remote repository, so others can use it:
git push origin <branchname>
Push all branches to your remote repository:
git push --all origin
Delete a branch on your remote repository:
git push origin :<branchname>
Fetch and merge changes on the remote server to your working directory:
To merge a different branch into your active branch:
git merge <branchname>
View all the merge conflicts:
View the conflicts against the base file:
Preview changes, before merging:
git diff --base <filename>
git diff <sourcebranch> <targetbranch>
After you have manually resolved any conflicts, you mark the changed file:
git add <filename>
TagsYou can use tagging to mark a significant changeset, such as a release:
git tag 1.0.0 <commitID>
Commit Id is the leading characters of the changeset ID, up to 10, but must be unique. Get the ID using:
Push all tags to remote repository:
git push --tags origin
If you mess up, you can replace the changes in your working tree with the last content in head:
Changes already added to the index, as well as new files, will be kept.
git checkout -- <filename>
Instead, to drop all your local changes and commits, fetch the latest history from the server and point your local master branch at it, do this:
git fetch origin git reset --hard origin/master