Difference between revisions of "Git"

From wiki
Jump to navigation Jump to search
Line 1: Line 1:
Using the [https://bitbucket.org/ Bitbucket] code repository with git.
+
=Using Git=
 +
Here is a basic overview of how you can work with git@bitbucket:
  
==Using Git==
+
* Add your public key in your profile - 'Personal Settings' - 'SSH keys'
Here is a basic overview of how you can work with git@bitbucket works:
 
  
 +
==Fresh project (nothing locally yet)==
 
* Create a "repository" (project) with a git hosting tool (like Bitbucket)
 
* Create a "repository" (project) with a git hosting tool (like Bitbucket)
::Add you public key in Settings - 'Access keys'
+
* <code>git clone <Look under the Clone Button</code> Copy (or clone) the repository to your local machine  
* Copy (or clone) the repository to your local machine <code>git clone <repoURL(replace https with ssh)></code>
+
* <code>git remote set-url --push origin <Look under the Clone Button></code> Set the push URL  
* Set push URL to https <code>git remote set-url --push origin <SSHrepoURL></code>
+
* <code>git add <filenname></code> Add a file to your local repository
* Add a file to your local repo and "commit" (save) the changes <code>git add <filenname></code>
+
* <code>git commit -m 'Reason for commit'</code> ]
* "Push" your changes to your master branch <code>git push</code>
+
* <code>git push</code> Send your changes to your master branch  
* Make a change to your file with a git hosting tool and commit
+
 
* "Pull" the changes to your local machine <code>git pull</code>
+
==For a project you have files for already==
 +
 
 +
* Create a "repository" (project) with a git hosting tool (like Bitbucket)
 +
* <code>git init</code> (initialize the local repository)
 +
* <code>git add .</code> (Add all file to the local repository)
 +
* <code>git commit -m 'Initial upload'</code> 
 +
* <code>git remote add origin <Look under the Clone Button></code>  (Connect local to remote repository)
 +
* <code>git push -u origin --all</code> (push all committed file to remote.
 +
 
 +
==Other things you can do==
 
* Create a "branch" (version), make a change, commit the change
 
* Create a "branch" (version), make a change, commit the change
 
* 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
  
 +
 +
=Other commands=
 
;<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 24: Line 36:
 
;<code>git add/rm <path></code>
 
;<code>git add/rm <path></code>
 
:Add or remove files from the list of files to be commited.
 
:Add or remove files from the list of files to be commited.
;<code>git commit</code>
+
;<code>git commit -m 'Reason for commit'</code>
 
:Commit changes (add/rm) to the local repository.
 
:Commit changes (add/rm) to the local repository.
 
;<code>git commit -a</code>
 
;<code>git commit -a</code>
Line 34: Line 46:
 
;<code>git pull</code>
 
;<code>git pull</code>
 
:Fetch all changes made remote<path>
 
:Fetch all changes made remote<path>
 
==Local setup==
 
Install the git tools: <code>apt-get install git</code>
 
 
Initialize your user with:
 
:a name: <code>git config --global user.name "Your Name"</code>
 
:and email: <code>git config --global user.email "user@domain.tld"</code>
 
 
Set line endings correctly: <code>git config --global core.autocrlf input</code>
 
 
You homedir now has a .gitconfig files with this information
 
;<code>git config -l</code>
 
:List your configuration on user level
 

Revision as of 10:21, 9 August 2020

Using Git

Here is a basic overview of how you can work with git@bitbucket:

  • 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 Button Copy (or clone) the repository to your local machine
  • git remote set-url --push origin <Look under the Clone Button> Set the push URL
  • git add <filenname> Add a file to your local repository
  • git commit -m 'Reason for commit' ]
  • git push Send 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 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


Other commands

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 commited.
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 reset HEAD <path>
Reset commit status for <path>
git push
Send the repository remote<path>
git pull
Fetch all changes made remote<path>