Git: Difference between revisions
Jump to navigation
Jump to search
| (5 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
=Using Git= | =Using Git= | ||
This [https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow Atlassian workflow] looks like a good way to work with git. | |||
Here is a basic overview of how you can work with git@bitbucket: | Here is a basic overview of how you can work with git@bitbucket: | ||
| Line 32: | Line 35: | ||
* Open a "pull request" (propose changes to the master branch) | * Open a "pull request" (propose changes to the master branch) | ||
* "Merge" your branch to the master branch | * "Merge" your branch to the master branch | ||
=Workflow making changes= | |||
;git pull | |||
:Update from remote | |||
;git checkout -b <branchname> | |||
:Create a new branch | |||
;git status | |||
:Check if something changed | |||
;git add --all | |||
:Add all changed files to the repository | |||
;git restore <file> | |||
:Restore a file to it's last committed stage | |||
;git commit -m "Message" | |||
:Commit your changes | |||
;git push | |||
:Upload your repository | |||
When you are ready with your change | |||
;git checkout master | |||
:Go to the master branch | |||
;git pull | |||
:Update from remote, fix conflicts | |||
;git merge <branchname> | |||
:Update master with your changes, fix conflicts | |||
;git push | |||
:Update the remote repository | |||
=Other commands= | =Other commands= | ||
Check the [https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet cheatsheet] for more. | |||
;<code>git branch -d <brachname></code> | |||
:Delete a branch locally only | |||
;<code>git config --local -l</code> | ;<code>git config --local -l</code> | ||
:List your configuration for this repository (in the current directory). | :List your configuration for this repository (in the current directory). | ||
| Line 46: | Line 77: | ||
;<code>git commit -a</code> | ;<code>git commit -a</code> | ||
:Commit all local changes to the local repository. | :Commit all local changes to the local repository. | ||
;<code>git branch <branchname></code> | |||
:Create a new branche | |||
;<code>git checkout <branchname></code> | |||
:Make <branchename> current | |||
;<code>git checkout -b <branchname></code> | |||
:Make <branchename> and make it current (combine above 2 commands) | |||
;<code>git reset HEAD <path></code> | ;<code>git reset HEAD <path></code> | ||
:Reset commit status for <path> | :Reset commit status for <path> | ||
| Line 58: | Line 95: | ||
;<code>git pull</code> | ;<code>git pull</code> | ||
:Fetch all changes made remote and merge to current branch | :Fetch all changes made remote and merge to current branch | ||
;<code>git log</code> | |||
:Show all commits | |||
=Conflict resolution= | |||
Git merge tries to merge files from 2 branches when they differ. If that is not possible (e.g. as both files have changes in the same lines) the file will mark the conflicting parts. | |||
<<<<<<< HEAD | |||
Lines in the current branch | |||
======= | |||
Lines in the merged branch | |||
>>>>>>> <name of the merged branch> | |||
The ======= is the center of the conflict. Check which lines you want to be in and remove everything else (including the conflict markerd). | |||
Latest revision as of 06:58, 1 September 2026
Using Git
This Atlassian workflow looks like a good way to work with git.
Here is a basic overview of how you can work with git@bitbucket:
Initialize git on your computer:
git config --global user.name "<your name>"
git config --global user.email "<your emailaddress>"
- Add your public key in your profile - 'Personal Settings' - 'SSH keys'
Fresh project (nothing locally yet)
- Create a "repository" (project) with a git hosting tool (like Bitbucket)
git clone <Look under the Clone ButtonCopy (or clone) the repository to your local machinegit remote set-url --push origin <Look under the Clone Button>Set the push URLgit add <filenname>Add a file to your local repositorygit commit -m 'Reason for commit']git pushSend your changes to your master branch
For a project you have files for already
- Create a "repository" (project) with a git hosting tool (like Bitbucket)
git init(initialize the local repository)git pull <Repository URL(for bitbucket look under the Clone Button)>mastergit add .(Add all file to the local repository)git commit -m 'Initial upload'git remote add origin <Look under the Clone Button>(Connect local to remote repository)git push -u origin --all(push all committed file to remote.
Other things you can do
- Create a "branch" (version), make a change, commit the change
- Open a "pull request" (propose changes to the master branch)
- "Merge" your branch to the master branch
Workflow making changes
- git pull
- Update from remote
- git checkout -b <branchname>
- Create a new branch
- git status
- Check if something changed
- git add --all
- Add all changed files to the repository
- git restore <file>
- Restore a file to it's last committed stage
- git commit -m "Message"
- Commit your changes
- git push
- Upload your repository
When you are ready with your change
- git checkout master
- Go to the master branch
- git pull
- Update from remote, fix conflicts
- git merge <branchname>
- Update master with your changes, fix conflicts
- git push
- Update the remote repository
Other commands
Check the cheatsheet for more.
git branch -d <brachname>- Delete a branch locally only
git config --local -l- List your configuration for this repository (in the current directory).
git remote -v- Show 'remote' configuration.
git status -v- Show all difference between the current directory and the local repository.
git add/rm <path>- Add or remove files from the list of files to be committed (local files will be removed too).
git commit -m 'Reason for commit'- Commit changes (add/rm) to the local repository.
git commit -a- Commit all local changes to the local repository.
git branch <branchname>- Create a new branche
git checkout <branchname>- Make <branchename> current
git checkout -b <branchname>- Make <branchename> and make it current (combine above 2 commands)
git reset HEAD <path>- Reset commit status for <path>
git fetch- Fetch all changes made remote
git merge <branch>- Merge <branch> into the current branch
git branch --all- Show all branches in this repository
git push- Send the repository remote
git pull- Fetch all changes made remote and merge to current branch
git log- Show all commits
Conflict resolution
Git merge tries to merge files from 2 branches when they differ. If that is not possible (e.g. as both files have changes in the same lines) the file will mark the conflicting parts.
<<<<<<< HEAD Lines in the current branch ======= Lines in the merged branch >>>>>>> <name of the merged branch>
The ======= is the center of the conflict. Check which lines you want to be in and remove everything else (including the conflict markerd).