Git Workflow: Difference between revisions

From Littledamien Wiki
Jump to navigation Jump to search
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Overview==
==Overview==
Git Server set up on dbarchowsky.com.
Git Server set up on dbarchowsky.com.
[http://netbeans.org/kb/docs/ide/git.html NetBeans Git User Guide]
==Working with existing projects==
* Make sure the 'dev' drive is available on the current client. See [[#Configuration|Configuration]]
Using 'Git Bash' navigate to the project directory.
<syntaxhighlight lang="bash">
$ cd /m/littledamien/littledamien_web
</syntaxhighlight>
* To see a list of previous commits (which should include the branch names as part of the commit message):
<syntaxhighlight lang="bash">
$ git log --oneline
</syntaxhighlight>
* Make a new Git branch
: Naming convention: 'tm' + sequential number
<syntaxhighlight lang="bash">
$ git co -b mynewbranch
</syntaxhighlight>
* Edit as necessary. Then verify changed files with
<syntaxhighlight lang="bash">
$ git status -s
</syntaxhighlight>
* Add edits to commit with
<syntaxhighlight lang="bash">
$ git add filename.ext
</syntaxhighlight>
* Stage a deleted file with
<syntaxhighlight lang="bash">
$ git add -u filename.ext
</syntaxhighlight>
* Revert files with
<syntaxhighlight lang="bash">
$ git co HEAD filename.ext
</syntaxhighlight>
* Verify edits with
<syntaxhighlight lang="bash">
$ git diff --cached
$ git diff --cached filename.ext
</syntaxhighlight>
* Commit the edits ('tm0001' being the branch name used to track projects)
<syntaxhighlight lang="bash">
# commit all edits
$ git commit -m "tm0001: commit message"
# switch to master branch
$ git co master
# merge edits into master branch
$ git merge tm0001
# clean up branch
$ git branch -d tm0001
</syntaxhighlight>
* Then move the commits to the main repo:
<syntaxhighlight lang="bash">
$ cd /n/git/littledamien/littledamien_web
$ git pull /m/littledamien/littledamien_web
$ # or
$ git push ssh://[uname]@[domain].com:[port]/refs/littledamien/littledamien_web
$ # or
$ git push ssh://[uname]@[domain].com:[port]/refs/littledamien/littledamien_web master
$ # or (after creating an alias in .ssh/config)
$ git push dbarchowsky:/refs/littledamien/littledamien_web
</syntaxhighlight>
==Deploying updates==
===SFTP client===
* WS_FTPro with SFTP
===Netbeans===
# Configure project to link it to SFTP connection.
## Right click on project > Properties
## Run Configuration > Remote Connection
## Run As: Remote Web Site (FTP, SFTP)
## Select existing connection, or make a new one.
::* Host Name, Port Name, User Name, Password: self-evident
::* Private Key File: [leave blank]
::* Known Hosts File: ~/.ssh/known_hosts
::* Initial Directory: /path/to/web_root
# Select files within Netbeans project tree, right click > Upload


==Creating a new repo out of an existing site==
==Creating a new repo out of an existing site==
Line 77: Line 167:
</syntaxhighlight>
</syntaxhighlight>


==Working with existing projects==
==Configuration==
* Make sure the 'dev' drive is available on the current client. See [[#Configuration|Configuration]]
 
Using 'Git Bash' navigate to the project directory.
<syntaxhighlight lang="bash">
$ cd /m/littledamien/littledamien_web
</syntaxhighlight>
 
* To see a list of previous commits (which should include the branch names as part of the commit message):
<syntaxhighlight lang="bash">
$ git log --oneline
</syntaxhighlight>
 
* Make a new Git branch
<syntaxhighlight lang="bash">
$ git co -b mynewbranch
</syntaxhighlight>
 
* Edit as necessary. Then verify changed files with
<syntaxhighlight lang="bash">
$ git status -s
</syntaxhighlight>
 
* Add edits to commit with
<syntaxhighlight lang="bash">
$ git add filename.ext
</syntaxhighlight>
 
* Revert files with
<syntaxhighlight lang="bash">
$ git co HEAD filename.ext
</syntaxhighlight>


* Verify edits with
===Showing git settings===
<syntaxhighlight lang="bash">
$ git diff --cached
$ git diff --cached filename.ext
</syntaxhighlight>


* Commit the edits ('tm0001' being the branch name used to track projects)
Show all
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
# commit all edits
$ git config --list
$ git commit -m "tm0001: commit message"
 
# switch to master branch
$ git co master
 
# merge edits into master branch
$ git merge tm0001
 
# clean up branch
$ git branch -d tm0001
</syntaxhighlight>
</syntaxhighlight>


* Then move the commits to the main repo:
Show a specific setting
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
$ cd /n/git/littledamien/littledamien_web
$ git config user.name
$ git pull /m/littledamien/littledamien_web
$ # or
$ git push ssh://[uname]@[domain].com:[port]/refs/littledamien/littledamien_web
$ # or
$ git push ssh://[uname]@[domain].com:[port]/refs/littledamien/littledamien_web master
</syntaxhighlight>
</syntaxhighlight>


==Deploying updates==
==='littledamienii' repo setup===
===SFTP client===
* WS_FTPro with SFTP
 
===Netbeans===
# Configure project to link it to SFTP connection.
## Right click on project > Properties
## Run Configuration > Remote Connection
## Select existing connection, or make a new one.
# Select files within Netbeans project tree, right click > Upload
 
==Configuration==
* Make sure the 'dev' drive is available while working with Git Bash on the current client.  
* Make sure the 'dev' drive is available while working with Git Bash on the current client.  
<syntaxhighlight lang="dos">
<syntaxhighlight lang="dos">
Line 184: Line 213:




[[Category:GIT]]
[[Category:Git]] [[Category:Web Development]]

Latest revision as of 23:40, 23 April 2013

Overview[edit]

Git Server set up on dbarchowsky.com.

NetBeans Git User Guide

Working with existing projects[edit]

  • Make sure the 'dev' drive is available on the current client. See Configuration

Using 'Git Bash' navigate to the project directory.

$ cd /m/littledamien/littledamien_web
  • To see a list of previous commits (which should include the branch names as part of the commit message):
$ git log --oneline
  • Make a new Git branch
Naming convention: 'tm' + sequential number
$ git co -b mynewbranch
  • Edit as necessary. Then verify changed files with
$ git status -s
  • Add edits to commit with
$ git add filename.ext
  • Stage a deleted file with
$ git add -u filename.ext
  • Revert files with
$ git co HEAD filename.ext
  • Verify edits with
$ git diff --cached
$ git diff --cached filename.ext
  • Commit the edits ('tm0001' being the branch name used to track projects)
# commit all edits
$ git commit -m "tm0001: commit message"

# switch to master branch
$ git co master

# merge edits into master branch
$ git merge tm0001

# clean up branch
$ git branch -d tm0001
  • Then move the commits to the main repo:
$ cd /n/git/littledamien/littledamien_web
$ git pull /m/littledamien/littledamien_web
$ # or 
$ git push ssh://[uname]@[domain].com:[port]/refs/littledamien/littledamien_web 
$ # or 
$ git push ssh://[uname]@[domain].com:[port]/refs/littledamien/littledamien_web master
$ # or (after creating an alias in .ssh/config)
$ git push dbarchowsky:/refs/littledamien/littledamien_web

Deploying updates[edit]

SFTP client[edit]

  • WS_FTPro with SFTP

Netbeans[edit]

  1. Configure project to link it to SFTP connection.
    1. Right click on project > Properties
    2. Run Configuration > Remote Connection
    3. Run As: Remote Web Site (FTP, SFTP)
    4. Select existing connection, or make a new one.
  • Host Name, Port Name, User Name, Password: self-evident
  • Private Key File: [leave blank]
  • Known Hosts File: ~/.ssh/known_hosts
  • Initial Directory: /path/to/web_root
  1. Select files within Netbeans project tree, right click > Upload

Creating a new repo out of an existing site[edit]

Creating the Git repos[edit]

  • Navigate to the site's root directory.
  • Create a Git repository.
$ git init
  • Make a .gitignore file (images, wordpress install files, etc.)
Copy from an existing web project and modify as necessary.
  • Set username and email (necessary for each repo)
$ git config --global user.name "Damien Barchowsky"
$ git config --global user.email "dbarchowsky@gmail.com"
  • Add existing files to Git repo, confirm the list of files, and commit the changes.
$ git add .
$ git status -s
$ git commit -m "Initial version"
  • Clone the repo to 'origin'
$ cd /n/git/base_dir
$ git clone /m/base_dir/repo_dir

Configure SSH to allow Git to push to the production server with non-standard port number[edit]

Host sitealias
HostName domainname.com
Port 12345
User siteuser
  • then you should be able to use the basic syntax:
git push sitealias:/path/to/public_html master

Deploy a project using Git push[edit]

Note: this is not available with shared hosting. Changes must be uploaded with FTP. Refer to this thread on the NameCheap forums.

Stackoverflow: Deploy a project using Git push

1. Copy over your .git directory to your web server

Make sure to disallow access to any files within the .git directory!
Put an .htaccess file in the .git directory with
deny from all

2. On your local copy, modify your .git/config file and add your web server as a remote:

[remote "production"]
    url = username@webserver:/path/to/htdocs/.git

3. On the server, replace .git/hooks/post-update with this file

4. Add execute access to the file (again, on the server):

chmod +x .git/hooks/post-update

5. Now, just locally push to your web server and it should automatically update the working copy:

git push production

Configuration[edit]

Showing git settings[edit]

Show all

$ git config --list

Show a specific setting

$ git config user.name

'littledamienii' repo setup[edit]

  • Make sure the 'dev' drive is available while working with Git Bash on the current client.
subst m: "\\littledamienii\develop"
subst n: "\\littledamienii\shared"
  • Physical origin repos located beneath d:\shared\git
  • To make a new project:
d:
cd \shared\git
git clone ..\..\develop\path\to\project_root
cd .\path\to\project_root
git init 
rem <<< is that last 'git init' step necessary ??? >>>
  • At least for now, when fetching & pulling vial ssh, the root directory is the Git install directory (C:\Git).
  • A symbolic link has been created between C:\Git directory and the Git base directory (D:\shared\git)
cd \Git
mklink /d "refs" "d:\shared\git"
rem symbolic link created for refs <<===>> d:\shared\git
  • The symbolic link allows access to the git repo via
git clone|push|pull|etc. ssh://username@server/refs/path/to/myrepo