-
Notifications
You must be signed in to change notification settings - Fork 34
How to use git
The command used for adding files to git is git add
.
Examples:
git add source/common/core/Registry.cpp source/common/core/Color.cpp
git add .
The latter (git add .
) is only possible because we have a .gitignore
file.
It adds every file changed recursively from working directory.
Please update it if you add files you don't want to commit, but only if you want to use git add .
.
The command used to commit is git commit
.
Examples:
git commit
git commit -a
git commit -m "my commit message"
git commit -am "my commit message"
If you don't provide -m <commit_message
, git will open an editor using your env variable EDITOR
for you to write your commit message.
The first line is the general commit message and the third line + below are for details.
Just save and quit from the editor to save the commit (Ctrl+O then Ctrl+X if you use nano
which is the default for most Linux distributions).
The option -a
will automatically git add
all the modified files but won't add new ones.
To push local commits to a repo, you need to use git push
.
Examples:
git push
git push -u origin master
git push origin master
git push origin +master
Basic syntax is git push <remote> <branch>
. Use git remote -v
to see your remotes.
Option -u
sets the current upstream to <remote>/<branch>
, and allows you to only use git push
after that.
You can force push to a branch by prepending +
to the branch name.
Warning: Force-pushing overwrites all the branch with your local copy, use it wisely.
The command used for managing remotes is git remote
.
Examples:
git remote -v
git remote add origin [email protected]:Unarelith/OpenMiner
git remote set-url origin https://github.com/Unarelith/GameKit
git remote set-url --push origin https://github.com/Unarelith/GameKit
git remote remove origin
The first one, git remote -v
prints the remote list.
To add a remote, the command syntax is git remote add <remote> <url>
.
URLs can have the following syntaxes:
git://<server>/<user>/<repo> # uses HTTP
https://<server>/<user>/<repo> # uses HTTPS
git@<server>:<user>/<repo> # uses SSH
The third one is similar: git remote set-url <remote> <url>
.
You can use --push
to only change push URL (fetch URL will still be the same as before). This allows fetching using HTTP and pushing using SSH for example.
And the fourth one is very basic: git remote remove <remote>
.
On Linux, you can generate an SSH key using this command:
ssh-keygen -t rsa -b 4096 -C "[email protected]" # replace with your GitHub email
When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location.
At the prompt, type a secure passphrase. For more information, see "Working with SSH key passphrases".
To add your SSH public key to GitHub follow this guide.
Never use git pull
, please.
First, do a git fetch upstream master
(upstream
should be a remote pointing to this repo).
Then, run git status
. If you see that the branch has diverged, you'll maybe have some conflict management to handle.
Now run git rebase upstream/master
.
git rebase upstream/master
will go through all the commits that diverged from upstream/master
and try to fix conflicts itself based on the commits.
Sometimes, it's not able to fix the conflicts and ask you to do it instead.
Usually, git rebase
will output lines stating with CONFLICT
when it needs your help.
- Just open all those files and fix the conflicts there (
<<<<<<<
to=========
and to>>>>>>>>>
) - Use
git add
on the fixed files - Use
git rebase --continue
to move on to the next commit