Include:Git Basics: Difference between revisions
Prabuanand (talk | contribs) (Moved. So removed the Move message) Tag: Manual revert |
Prabuanand (talk | contribs) (moved Cloning your forked repository to Git page) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== Stashing == | <!-- This page is transcluded in [[Git]]. Do not change heading levels. Add new git options keeping the heading levels consistent. --> | ||
=== Stashing === | |||
{{Cmd|git stash}} if you want to "hide" your changes. Do this if you think there may be other commits against the same things you are working on and want to refresh your local checkout (using a <tt>git pull --rebase</tt>) from the master. Use <tt>git stash apply</tt> to get your stash back. | {{Cmd|git stash}} if you want to "hide" your changes. Do this if you think there may be other commits against the same things you are working on and want to refresh your local checkout (using a <tt>git pull --rebase</tt>) from the master. Use <tt>git stash apply</tt> to get your stash back. | ||
== Reset your local repository == | === Reset your local repository === | ||
{{Cmd|git checkout -f master}} if you think your tree is pretty hopeless, need a kill-and-fill to bring the master into your local repository. You will lose local changes. | {{Cmd|git checkout -f master}} if you think your tree is pretty hopeless, need a kill-and-fill to bring the master into your local repository. You will lose local changes. | ||
== List the local branch == | === List the local branch === | ||
You can now list your local branch by doing | You can now list your local branch by doing | ||
{{Cmd|git branch}} | {{Cmd|git branch}} | ||
Line 13: | Line 15: | ||
* master | * master | ||
== List your local non committed changes == | === List your local non committed changes === | ||
{{Cmd|git status}} | {{Cmd|git status}} | ||
== Commit == | === Commit === | ||
Now you can start to work on your tree. As soon as you feel you have reached a step in development where you can commit your work '''locally''', use | Now you can start to work on your tree. As soon as you feel you have reached a step in development where you can commit your work '''locally''', use | ||
{{Cmd|git commit -a}} | {{Cmd|git commit -a}} | ||
Line 39: | Line 43: | ||
fixes #<issuenumber> | fixes #<issuenumber> | ||
Think of first line as the subject in an email and the third line and on as the body of the email, describing what the commit does. You don't need the long description but the first line, the short description should be there as it will be showed in the commit log. | Think of first line as the subject in an email and the third line and on as the body of the email, describing what the commit does. You don't need the long description but the first line, the short description should be there as it will be showed in the commit log. | ||
Line 45: | Line 48: | ||
{{tip|You can add the following line to your {{path|~/.vimrc}}:<pre>autocmd FileType gitcommit set textwidth=72</pre> }} | {{tip|You can add the following line to your {{path|~/.vimrc}}:<pre>autocmd FileType gitcommit set textwidth=72</pre> }} | ||
== List your commits == | === List your commits === | ||
To view the list your commits: {{Cmd|git log}} | |||
To Check what you are going to push from local to remote: {{Cmd|git log origin..master}} | |||
=== Keeping your local working branch in sync === | |||
Pull the changes from upstream (git.alpinelinux.org) | Pull the changes from upstream (git.alpinelinux.org) | ||
{{Cmd|git pull --rebase}} | {{Cmd|git pull --rebase}} | ||
Line 55: | Line 60: | ||
Run the command: {{Cmd|git config branch.origin.rebase true}} Next time you do 'git pull' you are actually doing a 'git pull --rebase'.}} | Run the command: {{Cmd|git config branch.origin.rebase true}} Next time you do 'git pull' you are actually doing a 'git pull --rebase'.}} | ||
== Git Tag == | === Git Tag === | ||
Create an annotated tag and push it. | Create an annotated tag and push it. | ||
{{Cmd|git tag -a ''tagname'' -m 'commit message (e.g release 1.x)' | {{Cmd|git tag -a ''tagname'' -m 'commit message (e.g release 1.x)' | ||
git push && git push --tags}} | git push && git push --tags}} | ||
== Create a new project == | === Git push === | ||
To push your changes up to the master. {{Cmd|git push}} | |||
=== Create a new project === | |||
Create your own directory that you want to become your new acf-mystuff project. | Create your own directory that you want to become your new acf-mystuff project. | ||
{{Cmd|mkdir acf-mystuff | {{Cmd|mkdir acf-mystuff | ||
Line 70: | Line 80: | ||
{{Cmd|git add ./ | {{Cmd|git add ./ | ||
git commit}} | git commit}} | ||
=== Rebasing against upstream master === | |||
It's best to always stay up-to-date with the state of the upstream Alpine Linux repository to ensure that no merge conflicts happen later on. To do that you first have to add a new git remote which points to the upstream repository (instead of your fork): {{Cmd|git remote add upstream <nowiki>https://gitlab.alpinelinux.org/alpine/$REPO</nowiki>}} | |||
Now you can fetch all changes with:{{Cmd|git fetch --all}} | |||
And then you can rebase with:{{Cmd|git rebase}} | |||
[[Category:Development]] | [[Category:Development]] | ||
[[Category:Git]] | [[Category:Git]] |
Latest revision as of 09:38, 18 February 2025
Stashing
git stash
if you want to "hide" your changes. Do this if you think there may be other commits against the same things you are working on and want to refresh your local checkout (using a git pull --rebase) from the master. Use git stash apply to get your stash back.
Reset your local repository
git checkout -f master
if you think your tree is pretty hopeless, need a kill-and-fill to bring the master into your local repository. You will lose local changes.
List the local branch
You can now list your local branch by doing
git branch
which should ouput
* master
List your local non committed changes
git status
Commit
Now you can start to work on your tree. As soon as you feel you have reached a step in development where you can commit your work locally, use
git commit -a
or
git commit <specific files>
or
git add <specific files> git commit
If you wish to give credit to someone else's work (e.g. you are applying a third party patch):
git commit <specific files> --author "Name Surname <user@example.com>
The format of the commit message should be:
One-line description that's less than 72 chars long <second line empty> Optional longer description with explanation why changes were made. Links to relevant issues in Bugtracker can be done with: ref #<issuenumber> It is also possible to resolve issues with: fixes #<issuenumber>
Think of first line as the subject in an email and the third line and on as the body of the email, describing what the commit does. You don't need the long description but the first line, the short description should be there as it will be showed in the commit log.
autocmd FileType gitcommit set textwidth=72
List your commits
To view the list your commits:
git log
To Check what you are going to push from local to remote:
git log origin..master
Keeping your local working branch in sync
Pull the changes from upstream (git.alpinelinux.org)
git pull --rebase
Run the command:
git config branch.origin.rebase true
Next time you do 'git pull' you are actually doing a 'git pull --rebase'.Git Tag
Create an annotated tag and push it.
git tag -a tagname -m 'commit message (e.g release 1.x)' git push && git push --tags
Git push
To push your changes up to the master.
git push
Create a new project
Create your own directory that you want to become your new acf-mystuff project.
mkdir acf-mystuff cd acf-mystuff git init
Create your files and add/commit them to your git-project
git add ./ git commit
Rebasing against upstream master
It's best to always stay up-to-date with the state of the upstream Alpine Linux repository to ensure that no merge conflicts happen later on. To do that you first have to add a new git remote which points to the upstream repository (instead of your fork):
git remote add upstream https://gitlab.alpinelinux.org/alpine/$REPO
Now you can fetch all changes with:
git fetch --all
And then you can rebase with:
git rebase